Image

Programs - Java - Core Java - File Handling

Program:


package FileHandling;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;


public class copyFile {

public static void main(String args[])
{
File f=new File("f:SerExm.java");
File f1=new File("f:Ser.java");

  try {
    FileInputStream in =new FileInputStream(f);
   
    
    FileOutputStream out=new FileOutputStream(f1);
  int i;
  while((i=in.read())!=-1)
    {
      out.write((char)i);
    }
    
  } catch (FileNotFoundException ex) {
    Logger.getLogger(copyFile.class.getName()).log(Level.SEVERE, null, ex);
  } catch (IOException ex) {
    Logger.getLogger(copyFile.class.getName()).log(Level.SEVERE, null, ex);
  }

}
}