File Copy

File Copy


 // File handling in java

// Copy from source file to destination file


import java.io.*;


class FH

{

public static void main(String as[]) throws IOException

{

FileInputStream fin = null;

FileOutputStream fout = null;

int i;

try

{

fin = new FileInputStream("ipt.txt");

fout = new FileOutputStream("opt.txt");

while(true)

{

i = fin.read();

if(i==-1)

break;

fout.write((char)i);

}

System.out.println("File copied successfully.");

}

catch(Exception e)

{

System.out.println(e);

}

finally

{

if(fin!=null)

fin.close();

if(fout!=null)

fout.close();

System.out.println("End of pgm.");

}

}

}

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu