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

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

 
0
  #1
Sep 29th, 2008
  1. import java.util.Scanner;
  2. import java.io.*;
  3.  
  4. public class program1 {
  5. 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)throws IOException {
  15.  
  16. printFile();
  17.  
  18. }
  19.  
  20. public static void printFile()throws IOException {
  21. int num;
  22.  
  23. while(filescan.hasNextInt()){
  24.  
  25. num= filescan.nextInt();
  26. System.out.print(num+" ");
  27. }
  28.  
  29. }
  30.  
  31. }

I've been battling with tryin to figure out how to use the scanner object "filescan" througout all my functions. can someone please direct on how to do this. im sure im not too far from getting it right.

thanks

when i attempt top use "filesan" in the print file method i get ------->
Cannot make a static reference to the non-static field filescan

but i need this method to be static so that i may call it in the main?
not sure on what needs to be done at this point
Reply With Quote