
java program using filereader and filewriter

Hi Friend,
Try the following code:
import java.io.*;
class FileInputStreamAndFileOutputStream
{
public static void main(String[] args) throws Exception {
FileInputStream in = new FileInputStream("c:/hello.txt");
FileOutputStream out = new FileOutputStream("C:/data.txt");
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
out.close();
System.out.println("File is copied");
}
}
Thanks

Hi Friend,
Try the following code:
import java.io.*;
class FileReaderAndFileWriter{
public static void main(String[] args) throws IOException {
FileReader in = new FileReader("C:/Hello.txt");
FileWriter out = new FileWriter("C:/new.txt");
int c;
while ((c = in.read()) != -1){
out.write(c);
}
out.close();
System.out.println("File is copied");
}
}
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.