Search This Blog

Friday, 12 September 2014

Read word by word from file - JAVA

How to Read word by word from file in Java - File Handling in java

This program shows how to Read word by word from a file and display each word to console in Java.

Testing_.java

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Testing_
{
    public static void main(String args[]) throws FileNotFoundException{
     Scanner scanner = new Scanner(new File("myFile.txt"));
     while(scanner.hasNext())System.out.print(scanner.next());//Get next Word
     scanner.close();
    }
}

No comments:

Post a Comment