自分のプログラムに、ファイルの一部を読み込んでHTML用にフォーマットするスキャナがあります。ファイルを読んでいるときに、スキャナが行末にあることをスキャナに知らせる方法を知り、次の行に書き始める必要があります。ここでスキャナで行の終わりを判断するのに助けが必要
は私のコードの関連部分で、私は何を残した場合、私に知らせて:
//scanner object to read the input file
Scanner sc = new Scanner(file);
//filewriter object for writing to the output file
FileWriter fWrite = new FileWriter(outFile);
//Reads in the input file 1 word at a time and decides how to
////add it to the output file
while (sc.hasNext() == true)
{
String tempString = sc.next();
if (colorMap.containsKey(tempString) == true)
{
String word = tempString;
String color = colorMap.get(word);
String codeOut = colorize(word, color);
fWrite.write(codeOut + " ");
}
else
{
fWrite.write(tempString + " ");
}
}
//closes the files
reader.close();
fWrite.close();
sc.close();
[OK]を、私は)(sc.nextLine知った;,私はまだ知りません私がいつ行末にいるかを判断する方法。
ヒント:あなたの投稿のタイトルを特定の質問にしてください。 – nes1983
最後にsc.hasNext()がfalseになると、そうですか? – kosa
あなたは 'FileWriter'を別の行に書き始める方法を知りたくありませんか?あなたの記事から、Scannerに必要な機能が備わっているので、そのようにすることができます。 –