Users Pricing

forum

home / developersection / forums / read a .txt file and return a list of words with their frequency in the file

Read a .txt file and return a list of words with their frequency in the file

Anonymous User 2073 30 Dec 2014
I have this so far but it only prints the .txt file to the screen:

import java.io.*;

public class ReadFile {
    public static void main(String[] args) throws IOException {
        String Wordlist;
        int Frequency;

        File file = new File("file1.txt");
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
        String line = null;

        while( (line = br.readLine()) != null) {
            String [] tokens = line.split("\\s+");
            System.out.println(line);
        }
    }
}
Can anyone help me so it prints a word list and the words frequency?

I am a content writter !


1 Answers