Differences

This shows you the differences between two versions of the page.

Link to this comparison view

javadir [2014/10/26 01:52] (current)
Line 1: Line 1:
 +===== Dir listing in Java =====
 +<code 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]);​
 +            }
 +        }
 +    }
 +}
 +</​code>​
 +
 +----
 +
 +  * [[javainfo|Back to Java]]
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