关于system.in控制台输入循环不终止

public class SetTest {

public static void main(String[] args) throws IOException {
    Set<String> hashset=new HashSet<>();
    long totalTime=0;
    //int count=0;
    Scanner in=new Scanner(Paths.get("c:\\Users\\xiao\\Desktop\\test.txt"));
    //Scanner in=new Scanner(System.in);
    while(in.hasNext()){
        String word=in.next();
        System.out.println(word);
        long callTime=System.currentTimeMillis();
        hashset.add(word);
        callTime=System.currentTimeMillis()-callTime;
        totalTime+=callTime;
    }

    System.out.println(hashset.size());
    Iterator<String> iterator =hashset.iterator();
    for(int i=1;i<=20&&iterator.hasNext();i++){
        System.out.println(iterator.next());
    }
    System.out.println("...");
    System.out.println(hashset.size()+" distinct words."+totalTime+" milliseconds");
}

}
第一个循环一直跳不出来,控制台也没有结束,为什么呢,谢谢各位大哥

注释错了,从文件读入是可以结束的,从控制台读入不可以。注释错位置了

程序没有问题,我运行了正常。
看看你的包导入有没有问题:
import java.io.IOException;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

我测试运行没问题呢,可能是导包错了,或者是文件太长?