Excersise :10 Read and Write Operation | Java | Tamizhan Goals

Read and write operation

Excersise:10

    Read and Write the content of a file using I/O Packages

Program


import java.io.*;
Class CopyFile
{
public static void main(String arg[])throws IOException
{
int i;
FileInputStream fin;
FileOutputStream fout;
try
{
try
{
fin=new FileInputStream(arg[0]);
}
catch(FileNotFoundException e)
{
System.out.println("File not found");
return;
}
try
{
fout=new FileOutputStream(arg[1]);
}
catch(FileNotFoundException e)
{
System.out.println("Error opening output file");
return;
}
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("WELCOME TO INFO-TECH");
return;
}
try
{
do
{
i=fin.read();
if(i!=-1)
fout.write(i);
}
while(i!=-1);
}
catch(IOException e)
{
System.out.println("File Error");
}
fin.close();
fout.close();
}
}

Output

Post a Comment

Thanks for your comments. Please be visit and given positive review on our site.

Previous Post Next Post