Tuesday, August 4, 2015

[Java] Retrieve all Files inside a Directory

Below code can be used to retrieve all files inside a directory.




public static ArrayList<String> getAllFiles(String directory){
ArrayList<String> listOfFiles = new ArrayList<String>();
File fileDirectory = new File(directory);
for (final File fileEntry : fileDirectory.listFiles()) {
if(fileEntry.isFile()){
listOfFiles.add(fileDirectory.getAbsolutePath()+ "/" + fileEntry.getName()); //Add absolute path.
}
}
return listOfFiles;
}

No comments:

Post a Comment