these are the errors i have gotten now sir ( after removing exceptions)
java.io.FileNotFoundException: t.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at program1.main(program1.java:17)
Exception in thread "main" java.lang.NullPointerException
at program1.printFile(program1.java:29)
at program1.main(program1.java:22)
import java.util.Scanner;
import java.io.*;
public class program1 {
static Scanner filescan = null;
public program1(){
/*try {
filescan = new Scanner (new File("t.txt"));
} catch (FileNotFoundException fe){
fe.printStackTrace();
}*/
}
public static void main(String[] args){
try {
filescan = new Scanner (new File("t.txt"));
} catch (FileNotFoundException fe){
fe.printStackTrace();
}
printFile();
}
public static void printFile(){
while(filescan.hasNextInt())
System.out.println(filescan.nextInt());
}
}