Read next word in java

前端 未结 5 1451
广开言路
广开言路 2020-11-27 18:08

I have a text file that has following content:

ac und
accipio annehmen
ad zu
adeo hinzugehen
...

I read the text file and iterate through t

5条回答
  •  囚心锁ツ
    2020-11-27 19:02

    You can just use Scanner to read word by word, Scanner.next() reads the next word

    try {
      Scanner s = new Scanner(new File(filename));
    
      while (s.hasNext()) {
        System.out.println("word:" + s.next());
      }
    } catch (IOException e) {
      System.out.println("Error accessing input file!");
    }
    

提交回复
热议问题