Wednesday 11 February 2015

Read One File And Write Other File

In this Program we two file and we copy data of first.txt file in second.txt file using java code

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyData {

    public static void main(String[] args) throws IOException {
    String pathInput="D:\\a\\first.txt";
    String pathOutput="D:\\a\\second.txt";
    FileInputStream in=null;
    FileOutputStream out=null;
    try {
        in=new FileInputStream(pathInput);
        out=new FileOutputStream(pathOutput);
        int c;
        while ((c=in.read())!=-1) {
            out.write(c);
        }
    } catch (Exception e) {
        System.out.println(e);
    }finally{
        if (!(in==null)) {
            in.close();
        }
        if (!(out==null)) {
            out.close();
        }
       
    }
    System.out.println("Copy Data");
}
   
}

No comments:

Post a Comment