我经常使用扫描仪课程。但是在这种情况下,一个圆圈while(scanner..hasNext())返回任何东西。文件路径正确。可能是什么原因?我附上了代码和文件的内容。
public class Solution {
public static void main(String[] args) throws IOException{
File file = new File("D:/t1.txt");
Scanner sc = new Scanner(file);
sc.useDelimiter("\\s");
while (sc.hasNext()){
String ss = sc.next();
System.out.println(ss);
}
sc.close();
}
}
文件t1.txt
Киев Нью-Йорк Амстердам Вена Мельбурн
这可能与您的问题无关,但是您应该始终指定字符集
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句