Dir listing in Java

import java.io.*;
 
public class Dir
{
    public static void main(String args[])
    {
        String path = "/home/madan/";
        String filter = "*.txt";
 
        FilenameFilter filt = new FilenameFilter() {
            public boolean accept(File p, String f) {
                String onlyUniverse = ".txt";
                boolean b = f.endsWith(onlyUniverse);
                return b;
            }
        };
 
        File dir = new File(path);
 
        String[] children = dir.list(filt);
        if (children == null) {
            System.out.println(path+ " *ERROR* - cannot access");
        } else {
            for (int i=0; i<children.length; i++) {
                System.out.println(children[i]);
            }
        }
    }
}

javadir.txt · Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0