开发者

Unable to read a directory using File.list()

I was hoping to get a list of all files and folders in a directory using java without using system calls.

I tried:

import java.io.File开发者_StackOverflow中文版;
import java.util.Arrays;


public class test {

/**
 * @param args
 */
public static void main(String[] args) {
File fileDir = new File("directory");
String[] fileNames = fileDir.list();
System.out.println(Arrays.toString(fileDir.list()));
}
}

But it only returned 9 files out of many more. I tried with a Perl script and got the same result. I think there is something wrong with the directory, but I'm at a loss as to what.

I would really appreciate some help.


You are probably looking at wrong directory -> mind you are using relative path, which might be different than what you expect (print out fileDir.getAbsolutePath() to find out).


Declaring a file object pointing at "directory" means that the file object will end up pointing to <jvm running directory>/directory . The jvm running directory is generally whatever directory you launch the jvm from. Try using the full path to the directory and see if it works.

Otherwise, please provide some sample output as well as the expected output.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜