Previously we have discussed the Program for
This program is to read all files and files inside the folders for some period of time.In this program we have used the listFiles() method of File class which return all files and folders in array of File Type ,then we have used for loop to read all files and sub files .
import java.io.File;
public class ReadAllFiles {
static void readDir(String filePath){
long start = System.currentTimeMillis();
long end = System.currentTimeMillis() + 60 ;
File f = new File(filePath);
if(f.exists()){
File[] listFile = f.listFiles();
for(File name : listFile){
if(start > end){
System.err.println("TIME OUT");
System.exit(1);
}
else{
if(name.isDirectory()){
readDir(name.toString());
}
else{
System.out.println(name);
}
}
start++;
}
}
else{
System.err.println("PATH NOT FOUND");
}
}
public static void main(String[] args) {
readDir("D:/");
}
}
Java I/O Tutorial
No comments:
Post a Comment