Java 从包含字符串的主方法调用方法时出错

Java 从包含字符串的主方法调用方法时出错,java,Java,我在调用方法getValWords的程序中不断遇到此错误,错误显示如下“类型anothertry中的方法getValidWords(字符串)不适用于参数(文件)”。 这是我的代码示例 File file = new File (args[0]); List<String> words = getValidWords(file); Collections.sort(words); System.out.println(words.toString(

我在调用方法
getValWords
的程序中不断遇到此错误,错误显示如下“类型anothertry中的方法getValidWords(字符串)不适用于参数(文件)”。

这是我的代码示例

    File file = new File (args[0]);
    List<String> words = getValidWords(file);  
    Collections.sort(words);

    System.out.println(words.toString());

    }

public static String[] getValidWords(String s) {
    s = s.replaceAll("[0-9]\\p{L}+", " "); // Removes any word starting with a number
    s = s.replaceAll("\\s+", " "); // trims extra whitespace "    " into " "
    return s.split(" ");
}
File File=新文件(args[0]);
列表字=GetValidWord(文件);
集合。排序(单词);
System.out.println(words.toString());
}
公共静态字符串[]GetValidWord(字符串s){
s=s.replaceAll(“[0-9]\\p{L}+”,”);//删除任何以数字开头的单词
s=s.replaceAll(“\\s+”,“”);//将多余的空格“”修剪为“”
返回s.split(“”);
}

您必须首先获取文件内容并转换为字符串,然后调用此方法。

您认为该错误是什么意思?文件和字符串是不同的东西。您不能将
String[]
分配给
List
您忘记了一个步骤。见: