Switch to full style
General Java code examples
Post a reply

Read list of files in java I/O code

Wed Feb 06, 2013 8:09 pm

Read list of files in java I/O code class
java code
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;
}
}




Post a reply
  Related Posts  to : Read list of files in java I/O code
 How are Java source code files named     -  
 Read your gmail using Java code     -  
 simple code to read properties in java     -  
 How to read string text in files     -  
 program to read trace files     -  
 How to write a PHP coding to list out all files and director     -  
 Linked List C++ Code Implementation     -  
 list insertion sorting code in c++     -  
 can u check tis code to perform union & intersection of list     -  
 Read stream from URL using Java     -  

Topic Tags

Java Files and I/O