Source code
package pkg4;
import java.io.FileReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.PrintWriter;
public class Main {
public static void main(String[] args)
{
BufferedReader br = null;
String str;
try
{
br = new BufferedReader(new FileReader("input.txt")); //open file
PrintWriter pw = new PrintWriter("output.txt"); ///create file
while((str=br.readLine())!=null) ///read from input file
{
pw.println(str); ///write in output file
}
pw.close(); ///close the file
}
catch(IOException e)
{
System.out.println("File not open");
}
}
}
Output
input.txt:

output.txt:

Add your comment