Sunday, July 30, 2017

File read write example in Java

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

public class fileReadWrite {

           public static void main(String[] args) throws FileNotFoundException {

          File fileIn=new File("E:/input.txt");
          File fileOut=new File("E:/output.txt");

          FileInputStream fin=new FileInputStream(fileIn);
          FileOutputStream fio=new FileOutputStream(fileOut);

          int count;
          try {
              while((count=fin.read())!=-1){
             fio.write(count);
                }
          } catch (IOException e) {

             e.printStackTrace();
          }
    }

}