View Single Post
Join Date: Oct 2004
Posts: 26
Reputation: SyLk is an unknown quantity at this point 
Solved Threads: 0
SyLk SyLk is offline Offline
Light Poster

Re: please enlighten me on what i need to do to get this right

 
0
  #7
Sep 29th, 2008
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)

  1. import java.util.Scanner;
  2. import java.io.*;
  3.  
  4. public class program1 {
  5. static Scanner filescan = null;
  6.  
  7. public program1(){
  8. /*try {
  9. filescan = new Scanner (new File("t.txt"));
  10. } catch (FileNotFoundException fe){
  11. fe.printStackTrace();
  12. }*/
  13. }
  14. public static void main(String[] args){
  15.  
  16. try {
  17. filescan = new Scanner (new File("t.txt"));
  18. } catch (FileNotFoundException fe){
  19. fe.printStackTrace();
  20. }
  21.  
  22. printFile();
  23.  
  24. }
  25.  
  26. public static void printFile(){
  27.  
  28.  
  29. while(filescan.hasNextInt())
  30. System.out.println(filescan.nextInt());
  31.  
  32. }
  33.  
  34. }
Reply With Quote