Website Design United States, Website Design California, Website Designing United States, Website Designing California

EachInDirectory.java - Java

EachInDirectory.java calls a callback with the name of each file in a given directory

/** EachInDirectory.java calls a callback with the name of each file in a given directory
By Rowland http://home.comcast.net/~rowland3/
**/

import java.io.*;

class EachInDirectory {
public EachInDirectory(String dirSpec) {
File f= new File(dirSpec);
String files[]= f.list();
for (int i=0; i<files.length; i++)
try {
String fileSpec= dirSpec+ f.separator+ files[i];
callback(fileSpec);
} catch (Exception E) {
System.err.println("ERR EachInDirectory "+ files[i]+ ": "+ E.getMessage());
}
}

/** callback() - override in dervied class. called with each file name in directory.
Return false to stop scanning directory. **/
protected boolean callback(String fileSpec) throws Exception {
System.out.println(fileSpec);
return true;
}

/** main() test routine. Pass directory on command line. **/
public static void main(String args[]) {
new EachInDirectory(args[0]);
}
}

WEB DESIGN INDIA
42 B Malviya Nagar , New Delhi-110017

Skype: manmeetsi
Email: support.webdesignindia@gmail.com
Tel: 91-011-40502005, 9810067295

 















 


© 2008-2009 dotnet4all.com