使用扫描仪读取 txt 文件中的单词时跳线

Jump of Line while Reading words in a txt File with Scanner

我正在阅读扫描仪中的文字,但我需要知道扫描仪是否更改为以下行。这是一个进度条(计数线)。 你能帮助我吗?这是我的代码:

Pattern pattern = Pattern.compile("[^\p{Alpha}]+");
try (Scanner sc = new Scanner(file)) {
               while (sc.hasNext()) {
               sc.useDelimiter(pattern);
               long totalLines = countLines(f);//Method that count Lines
               System.out.println("Reading " + totalLines + "Lines...");
               word = sc.next();//here i need to know if the scanner jumps to next Line or not. 

使用扫描程序 class 中可用的 hasNextLine() and nextLine() 方法。

遍历 lines.For 每一行,使用 space 拆分并计算其中的单词数。