Q:

Walking a Linux/Unix filesystem with Java?

I need to create a Java util that will recurse its way through a Unix (and/or Linux) filesystem and build an object model of the directory structure, retrieve file info - size, created date, last accessed date etc - plus I need to retrieve info on the physical storage device the files are sitting on. Ideally, this util will be portable. I have no experience of the Java standard libraries and only limited experience of Unix OS.  
Are there Java standard libraries that will handle working with the Unix filesystem? Or am I going to have to make native calls through some API and then worry about portability?  What options do I have? 

A:

Check out Apache Commons IO and FileUtils.iterator() in particular. That'll allow you to navigate the file system. Using an iterator is better than building up a huge list of candidate files mainly because of the potential memory issues.
If you need particular access to symlinks, then this may not be enough, and you may want to check out an early release of JDK 7. I understand the file system with Java 7 will have some capabilities surrounding symlinks.
Note: many Unix filesystems will give you ctime, which is the inode creation date and not the file creation date.

A:

You can use: java.io.File for that it may not contain all the information you need ( like the information of the physical storage ) but it will help you to create most of the logic you need.
You may take a look at muucommander which is an open source file manager. They've already done a lot of work to make this kind of stuff, and the code is very clean and accesible. 
Here's a working sample:
import java.io.File;

public class FileWalkTest {
    public static void main(String[] args) {
        File file = new File("/Users/oscarreyes/code/");
        printInfo( file );
    }
    public static void printInfo( File dir ) {
        for( File child : dir.listFiles() ) {
            if( child.isDirectory() ) {
                System.out.println( "\n"+child.getAbsolutePath());
                printInfo( child );
            } else {
                System.out.printf("%s read:%s write:%s xecute:%s, size:%d lastModified:%d %n", child.getName(),  child.canRead(), child.canWrite(), child.canExecute(), child.length(), child.lastModified());
            }
       }
        System.out.println();

    }
}

A:

In JDK7, the new package java.nio.file provides useful utilities around files. In particular, the java.nio.file.Files class has walkFileTree(..) methods and other file-related utility functions.
See JDK7 API Doc: http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html

