Please help me get this work :(
(My objective is to count words in a file from input.txt file.)
I get 8 compiling errors in the following code. (All cannot find symbol) Compiler points out:
- The letter "P" in "Paths.get".
- The letter "F" in "Files.readAllLines"
- The symbol "." in "titleList.add(line)"
- The symbol "." in "titleList.get"
- The symbol "." in "st.add(filterList);"
- The symbol "." in "filterList.removelAll(stopWordsArray);"
- The letter "n" in "Map map = new Map< String, Integer>();"
- The symbol "." in "for (int i =0; i < map.length && i < 20; i++)"
Lines of code with errors are bold.
Any idea what is wrong with my code? I'm a beginer with java and help is greatly aprecited.
public String[] process() throws Exception {
String[] ret = new String[20];
//TODO
// Pass user id
initialRandomGenerator(this.userName);
// Get the index into array
Integer[] indexes = this.getIndexes();
// Create Array to store input.txt
String[] titleList = new String[10000];
// Put each line of input.txt in Array
// ERRORS HERE
**for (String line : Files.readAllLines(Paths.get(this.inputFileName))){
titleList.add(line);
}**
// Create array to store list of words to be proccess
String[] filterList = new String[50000];
// Look for words in file
for (int i = 0; i < indexes.length; i++){
// Tokennize, lower case, trim and stop delimiter.
// ERRORS HERE
**StringTokenizer st = new StringTokenizer(titleList.get(indexes[i]).trim().toLowerCase(), this.delimiters);**
// Add word to Filter list array
**st.add(filterList);**
}
// Remove stopWords from filter list array.
// ERRORS HERE
**filterList.removelAll(stopWordsArray);**
// Declaring the map to count
// ERRORS HERE
**Map<String, Integer> map = new Map< String, Integer>();**
// Loop to count
for (int i = 0; i < filterList.length; i++ ){
// Get the word
String word = filterList[i];
//Count the word
if (map.get(word) != null) {
// another occurence of an existing
// word
int count = map.get(word);
count++;
map.put(word, count);
} else {
// first occurence of this word
map.put(word, 1);
}
}
// Sort the list by frequency in a descending order. Use sort function.
// map.collections.sort( list, new Comparator<Map.Entry<word, count>>();
// Display first 20 words.
// ERRORS HERE
**for (int i =0; i < map.length && i < 20; i++){
System.out.println(filterList[i]);**
}
return ret;
}