我在我的程序中有一个扫描仪读取部分文件和格式为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();
好吧,我发现了关于sc.nextLine();,但我仍然不知道如何确定我什么时候在一行的结尾。
提示:使您的文章标题成为特定问题。 – nes1983 2012-02-08 23:18:16
当你在结束sc.hasNext()将是假的,不是吗? – kosa 2012-02-08 23:18:55
只是要清楚,你确定你不想知道如何让'FileWriter'开始写在另一行?从您的帖子可以采取这种方式,因为扫描仪具有您需要的功能。 – 2012-02-08 23:37:18