get files located on computer
I开发者_C百科s java able to access directories and their contents located on the computer it's run from? I know that there is a JFileChooser (Where the user can select files), and I know that you can store/open files with direct paths. But can java get all files and directories conntained with a folder?
Can java list file contents of directories stored on a hard drive?
You can get the files under any directory like this:
File[] files = new File("/some/path").listFiles();
You might also be interested in how to recursively list files in Java.
Yes, it can.
So long as the account used to execute the application has the right permissions.
Yes, it can. In addition to what Oded said, in the case of applets, you need to explicitly grant access to read and write to a hard drive.
You can use a filepath to a directory you want and you can do something like:
File directory = new File("PATH TO DIRECTORY");
File [] contents;
if (directory.isDirectory()) {
contents = directory.listFiles(); // returns an array containing the file and directory abstract paths.
}
精彩评论