Wed Feb 06, 2013 8:09 pm
import java.util.*;
import java.io.*;
public class ListOfFiles implements Enumeration {
private String[] listOfFiles;
private int current = 0;
public ListOfFiles(String[] listOfFiles) {
this.listOfFiles = listOfFiles;
}
public boolean hasMoreElements() {
if (current < listOfFiles.length)
return true;
else
return false;
}
public Object nextElement() {
InputStream in = null;
if (!hasMoreElements())
throw new NoSuchElementException(" list empty.");
else {
String nextElement = listOfFiles[current];
current++;
try {
in = new FileInputStream(nextElement);
} catch (FileNotFoundException e) {
System.err.println("Error reading file : " + nextElement);
}
}
return in;
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.