Sorry, maulin. I tried again with FileFilter. It worked well with the return type of File[]. The only thing I need to do is change File[] to String[]. I can only use a "for loop" to do it, as follows:
import java.io.*;
class MyFileFilter implements FileFilter {
public boolean accept(File f) {
return f.isDirectory();
}}
public class
Test {
public static void main(String[] s) {
File f = new File("c:" + File.separator);
File[] list = f.listFiles(new MyFileFilter());
String[] list2 = new String[list.length];
for(int i=0; i<list.length; i++){
list2[i] = list[i].getName();
System.out.println(list2[i]);
}
}
}
Are there any better way to change File[] to String[] directly?