-5
私のコードメソッドでは、scanner.hasNext()は常にfalseの結果を返します。私はデバッグされたコードを理解しました。誰が何が問題なのか知っていますか?私はファイルをチェックした。ファイルは文字列で始まります。java Scanner.hasNext always false
public class TextFileImplementor {
public static void main (String [] args){
System.out.println("Enter the name of file\n");
Scanner scanner = new Scanner(System.in);
File file = new File(scanner.nextLine());
try {
scanner = new Scanner(file);
StringBuilder stringBuilder = new StringBuilder();
while (scanner.hasNext()){
stringBuilder.append(scanner.nextLine());
}
String [] strings = stringBuilder.toString().split("\\. ");
File newFile = new File("new_" + file.getName());
FileWriter fileWriter = new FileWriter(newFile, true);
for (String string :
strings) {
if (string.length()<141){
fileWriter.write(string + "\n");
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
おそらくファイルが空ですか? –
'scanner.nextLine()'を呼び出す場合は、 'scanner.hasNextLine()'で確認してください。しかし、おそらく問題はありません。 –
@AndyTurnerがscanner.hasNextLine()に変更されました。問題は解決されていません。 –