public static void main(String[] args) throws IOException {
try
{
String target;
Scanner look = new Scanner("OED.txt");
while(look.hasNextLine()) {
target = look.nextLine();
System.out.println(target);
}
look.close();
}
catch (Exception e) {
System.out.println("Error in categorizing!");
}
}
我使用了相同的代码(向下精简)来打印.txt
文件中的所有行。它成功地打印出了行,并且我能够使用此框架根据行中的关键字将行分类到不同的文件中。经过前几次尝试后,代码将仅返回扫描文件的名称,而不是文本的每一行。如果我不对代码进行任何更改,这是怎么发生的?