I trust I'm posting this in the right forum. You nice people do consider 3 semesters of java still "new," right??
Anyway, I'm having a problem with Scanner. I have my program prompting me for a file name, and when I type in a file name and hit enter, the program does not seem like it's going to the next step. Now, when I step through in debug mode, it looks like it's making it to a few lines down, where I start scanning the file and counting the number of lines. But my lines variable goes waaaaay past the true number of lines in the file.
Anyway, what I don't understand, mainly, is why my program seems to get stuck. Is it because it's counting the lines? Also, why does it keep incrementing? My file has 10 lines...
Here's my code:
public static void main(String[] args) { String filename; int lines = 0; Scanner input_scan = new Scanner(System.in), file_scan; System.out.print("Enter a file name: "); filename = input_scan.next(); file_scan = new Scanner(filename); while (file_scan.hasNextLine()) lines++;
Here is everything in the text file I'm scanning:
1234 23 widget1
3456 123 widget2
4356 45 widget3
1056 1234 widget4
9999 237 widget5
9322 22 widget6
5322 755 widget7
3422 2 widget8
3333 95 widget9
1111 15 widget10
That's it.
Any help would be greatly appreciated!