File Name - "FILE_MAIN.java"
Output of this program is as same as compiled program. It's open program file and print complete program copy as a output.
Program Code
//program output is program itself which compiled
import java.util.*; import java.io.*; public class FILE_MAIN { public static void main(String[] args) throws FileNotFoundException { FileReader dataFile = new FileReader("FILE_MAIN.java"); Scanner FileRead = new Scanner(dataFile); while (FileRead.hasNextLine()) { String Line1 = FileRead.nextLine(); System.out.println(Line1); } FileRead.close(); } }
Output
Save file name as "FILE_MAIN.java".
It is a example of File Handling. In this program output is same copy of program itself.
Hope, it's helpful to understanding Java file handling.