A method that tries to make a list of files in the argument folder into a String List.
FileUtils
import java.io.File;
import java.util.LinkedList;
import java.util.List;
public class FileUtils {
/**
*Returns the Path of the folder or file in the argument directory as a string List
*
* @param root
* @return
*/
public static List<String> getFileList(String root) {
return getFileList(new File(root));
}
/**
*
*Returns the Path of the folder or file in the argument directory as a string List
*
* @param root
* @return
*/
public static List<String> getFileList(File root) {
return getFileList(root, null);
}
/**
*
*Returns the Path of the folder or file in the argument directory as a string List
*
* @param root
* @param fileList
* @return
*/
private static List<String> getFileList(File root, List<String> fileList) {
//Returns null if the argument folder does not exist
if (root == null || !root.exists())
return null;
if (fileList == null)
fileList = new LinkedList<>();
if (root.isDirectory())
for (File f : root.listFiles())
fileList.addAll(getFileList(f, null));
else
fileList.add(root.getPath());
return fileList;
}
}
Recommended Posts