-1

我正在尝试使用具有特定文件类型(.dbf)的特定目录中的文件填充微调器。不幸的是,我不断收到错误“对于 ArrayList 类型的 toLowerCase() 方法未定义”。我该如何解决?

public ArrayList<String> ReadDirectory(){
String path="./database";

File folder = new File(path);
File[] ListOfFiles = folder.listFiles();

for (int i = 0; i < ListOfFiles.length; i++){
    if (ListOfFiles[i].isFile()){
        files.add(ListOfFiles[i].getName());
        if (files.endsWith(".dbf") || files.endsWith(".DBF")){
            }
    }
}
return files;
        }


}

此行给出错误:

if (files.endsWith(".dbf") || files.endsWith(".DBF")){

文件以下列方式在脚本顶部声明:

ArrayList<String> files = new ArrayList<String>();
4

3 回答 3

6

How do I solve the Java error: 'The Method toLowerCase() is undefined for the type ArrayList'

I cant see you using toLowerCase() method in your posted code. however, i assume you are trying to call toLowerCase() on a list reference. List doesnt have toLowerCase() method. String has toLowerCase() method.

you probably ment to do this:

List<String> list = new ArrayList<String>();
System.out.println(list.get(0).toLowerCase()); //this is legal
System.out.println(list.toLowerCase()); //this isn't legal as there is no toLowerCase() method in list
于 2012-12-18T12:28:16.297 回答
0

You can't use .endsWith() on a File. Considering you are using a for loop, you should go for files[i].endsWith(). However, using an enhanced for, e.g. for (File currentFile : files) is a more common approach.

Same thing goes for the .toLowerCase() method.

于 2012-12-18T12:32:12.263 回答
0

据我所知,toLowerCase() 仅针对字符串对象定义,因此在迭代期间从 ArrayList 中获取单个字符串,更改此字符串并替换 ArrayList 中的旧字符串

于 2012-12-18T12:30:14.937 回答