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 1641 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?

java java  file 
Updated on 30-Dec-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By