Anyone aware of a method/class/library that will allow me to easily reproduce the results of the *nix ls -l command in Java? Calling ls directly is not an option due to platform
Here's an implementation of ls -R ~
, which lists files recursively starting in the home directory:
import java.io.*;
public class ListDir {
public static void main(String args[]) {
File root;
if (args.length > 0) root = new File(args[0]);
else root = new File(System.getProperty("user.dir"));
ls(root);
}
/** iterate recursively */
private static void ls(File f) {
File[] list = f.listFiles();
for (File file : list) {
if (file.isDirectory()) ls(file);
else System.out.println(file);
}
}
}