
how to read the contents from one file and move the contents to another file

Hi Friend,
Try the following code:
import java.io.*;
import java.util.*;
public class ReadFile{
public static void main(String[]args)throws Exception {
File f=new File("data.txt");
FileInputStream fstream = new FileInputStream(f);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String str;
FileOutputStream fos=new FileOutputStream(new File("new.txt"));
while ((str = br.readLine()) != null) {
System.out.println(str);
fos.write(str.getBytes());
}
fos.close();
in.close();
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.