在一段时间内使用Scanner.hasNextLine时,main方法会无限重复

时间:2016-03-17 23:29:58

标签: java multithreading

使用" scanner.hasNextLine()"在线程内部,它会导致我的main方法无限重复。

以下是代码:

for (var i in imageCheer) {..}

我还要注意,当我使用" while(true)"我没有遇到这个问题。非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

像这样修改你的线程:

@Override
    public void run(){
        while(scanner.hasNextLine()){
            System.out.println("Has Next");
            scanner.nextLine();//move to next
        }
    }