I need to be able to have a method scan a line from a file and store this, so that in the driver class the method can be called to store the next line of the file, and then the  toString() method of the class can be used to print out the what was scanned. How would I do this?
            Asked
            
        
        
            Active
            
        
            Viewed 84 times
        
    -1
            
            
        - 
                    1You need to show the code you tried. – jeremyjjbrown Feb 26 '14 at 22:26
2 Answers
2
            Read a text file using java.util.Scanner
File file = new File("file.txt");
try {
    Scanner sc = new Scanner(file);
    while (sc.hasNextLine()) {
        int i = sc.nextInt();
        System.out.println(i);
    }
    sc.close();
} 
catch (FileNotFoundException e) {
    e.printStackTrace();
}
}
 
    
    
        Ima Vafaei
        
- 927
- 1
- 14
- 32
 
     
     
    