Search
 
SCRIPT & CODE EXAMPLE
 

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);
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: launch java batch 
Java :: android view set padding programmatically 
Java :: set text in edittext android 
Java :: if checkbox checked java 
Java :: arrays.sum 
Java :: draw circle with fill java 
Java :: java rgb to color 
Java :: reader 
Java :: abstract method declaration 
Java :: java for item in array 
Java :: Java Create a BufferedOutputStream 
Java :: align button to the left in JPanel 
Java :: Error:java: error reading C:UsersMeriem.m2 epositoryorgapachecommonscommons-lang33.12.0commons-lang3-3.12.0.jar; error in opening zip file 
Java :: How to merge two sorted arrays into a single sorted bigger one? 
Java :: jsp initialization 
Java :: jdialog middle of screen 
Java :: android arraylist to comma separated string 
Java :: Describe Methods Overloading in Java 
Java :: java convert double to boolean 
Java :: count true in matrix java 
Java :: fullscreen libgdx 
Java :: what are variables in java 
Java :: is the function same as method in java 
Java :: java set file folder permissions 
Java :: date java use fix timezone 
Java :: how to create dynamic string array in java 
Java :: Java Create a ByteArrayInputStream 
Java :: kotlin edittext default value 
Java :: null java 
Java :: stream filter java 8 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =