Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java read from file word by word

import java.util.Scanner;
import java.io.*;
 
public class ReadWords {
  public static void main(String[] args) throws IOException {
 
    File file = new File("words.txt");
    Scanner input = new Scanner(file); 
 
    int count = 0;
    while (input.hasNext()) {
      String word  = input.next();
      System.out.println(word);
      count = count + 1;
    }
    System.out.println("Word count: " + count);
  }
}
 
PREVIOUS NEXT
Tagged: #java #read #file #word #word
ADD COMMENT
Topic
Name
4+3 =