In this blog I am providing you the code for Copying content of one file to another file using java.

Below line of code is help to copy the content of source file to destination file.

public class CopyClass {
   public static void main(String[] args)
      InputStream in = new FileInputStream
      (new File("Source File"));
      OutputStream out = new FileOutputStream
      (new File("Destination File"));
      byte[] buf = new byte[1024];
      int len;
      while ((len = > 0) {
         out.write(buf, 0, len);
                System.out.println("File copied successfully!");
      BufferedReader in1 = new BufferedReader
      (new FileReader("destnfile"));
      String str;
      while ((str = in1.readLine()) != null) {
    catch(Exception ex){}

Note: - Before run above code you must be sure your source and destination file is available or not if this file is not available then you must create above file.

  Modified On Sep-18-2014 01:24:18 PM

Leave Comment