Java word counts: Error: Cannot find symbol. Java compiler

Java word counts: Error: Cannot find symbol. Java compiler

请帮我完成这项工作:(
(我的 objective 是从 input.txt 文件中计算文件中的单词数。)

我在以下代码中遇到了 8 个编译错误。 (都找不到符号) 编译器指出:

  1. "Paths.get"中的字母"P"。
  2. "Files.readAllLines"
  3. 中的字母"F"
  4. 符号“.”在 "titleList.add(line)"
  5. 符号“.”在 "titleList.get"
  6. 符号“.”在 "st.add(filterList);"
  7. 符号“.”在 "filterList.removelAll(stopWordsArray);"
  8. "Map map = new Map< String, Integer>();"
  9. 中的字母"n"
  10. 符号“.”在 "for (int i =0; i < map.length && i < 20; i++)"

有错误的代码行以粗体显示。

知道我的代码有什么问题吗?我是 java 的初学者,非常感谢帮助。

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

好的,所以我没用。这有点困难,因为无法使用 IDE 调试给定的文件。问题很简单。

我在以下代码中遇到了 8 个编译错误。 (都找不到符号)编译器指出:

1-"Paths.get"中的字母"P"。 (我需要导入库:import java.nio.file.Paths;)

2- "Files.readAllLines"中的字母"F" (我需要导入库:import java.nio.file.Files;)

3- 符号“.”在 "titleList.add(line)" (.add方法只适用于集合,例如ArrayList 我试图在数组中使用它。 )

4- 符号“.”在 "titleList.get"

(.get方法只适用于集合,例如ArrayList 我试图在数组中使用它。 )

5- 符号“.”在 "st.add(filterList);"

(.add方法只适用于集合,例如ArrayList 我试图在 StringTokenizer 中使用它)

6- 符号“.”在 "filterList.removelAll(stopWordsArray);"

(.get方法只适用于集合,例如ArrayList 我试图在数组中使用它。 )

7-"Map map = new Map< String, Integer>();"

中的字母"n"

(Map需要初始化为Map的一种,不只是Map,如HashMap)

8- 符号“.”在 "for (int i =0; i < map.length && i < 20; i++)"

(长度不是属性的地图;必须使用尺寸代替。)

亲切的问候