0
解決了,但我的聲望太低,無法回答我自己的問題。掃描儀(行)和掃描儀(System.in)行爲不端/人爲錯誤
掃描儀輸入; Scanner lineScanner;
input = new Scanner(System.in);
lineScanner = new Scanner(line);
String line;
char x;
askUserForInputFile(); //user selects input txt file. Method definitely works.
do {
line = input.nextLine();
if (line.length() < 6)
continue;
out.printf("debug0\n%s", line); //<----problem
do {
out.print("debug1\n");
x = lineScanner.next().charAt(0); //<-----problem
out.print("debug2\n");
//more code
我想逐行閱讀文件並僅在其長度()=> 6時進行處理。出現了什麼問題?
控制檯:
debug0
Exception in thread "main" <scanned line, displayed correctly>debug
java.util.NoSuchElementException
你確定這編譯? line:'lineScanner = new Scanner(line);' - 'line'定義在哪裏? –
也許你需要一個文件對象 –
我找到了解決方案,我需要在使用line.next()之前聲明String行。不幸的是,我沒有足夠的信譽來回答我自己的問題。 – user2979713