下面是我写的代码,bucketsRow
包含80个元素,for循环中的println语句正确显示了这一点。 readFile
是一个扫描程序,它遍历一个包含800行的文件,其中元素是第一个单词,bucketsRow
中存在任何80个单词。我希望复制到新文件中的那些行,我使用了filewriter。
for(int p=0;p<bucketsRow.length;p++)
{
System.out.println("p:"+p+"Doc at p:"+names[p]);
inner: while(readfile.hasNextLine())
{
String line=readfile.nextLine();
//System.out.println(line);
if(line.indexOf(names[p])!=-1)
{
System.out.println(line.indexOf(names[p]));
writefile.write(line);
writefile.write(System.getProperty( "line.separator" ));
break inner;
}
}
}
writefile.flush();
writefile.close();
答案 0 :(得分:1)
这里的问题是您需要再次将扫描仪类引用指针的焦点设置到文件的开头并再次开始比较。因此,输出文件中会遗漏一些行。
为了将焦点放在文件的开头,当您进入&#34;同时&#34;时,新建一个扫描仪参考。环。