我有以下代码:
while (FileOne.hasNextLine()){
String check = FileOne.nextLine();
Reader r = new FileReader("something");
mass1:
try{
Scanner FileTwo = new Scanner(r);
mass1:
while (FileTwo.hasNextLine()) {
String toCheck= FileTwo.nextLine().toString();
index1 = check.indexOf(toCheck);
if(index1 != -1){
index2++;
break mass1;
}//if(index1 != -1)
}//(it.hasNext())
}//try
finally {
r.close();
}//finally
}//while (FileOne.hasNextLine())
我想问: 当第二个 while 又名 while (FileTwo.hasNextLine) 结束时(有或没有中断命令),解析器下次转到该命令时,文件将从开头开始还是从上次的位置开始? 如果它不是从头开始那么我将如何让它从它开始(开始)?
最佳答案
它应该从头开始,因为您创建了一个新的扫描仪。
关于java - while 循环和文件流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7622517/