programming-examples/java/Core_Java/Check for Files.java
2019-11-15 12:59:38 +01:00

52 lines
1.7 KiB
Java

Check for Files
import java.io.*;
import java.util.*;
/**
* Create filelist.txt file by your self.
*/
public class CheckFiles {
public static void main(String[] argv) {
CheckFiles cf = new CheckFiles();
System.out.println("CheckFiles starting.");
cf.getListFromFile();
cf.getListFromDirectory();
cf.reportMissingFiles();
System.out.println("CheckFiles done.");
}
public String FILENAME = "filelist.txt";
protected ArrayList listFromFile;
protected ArrayList listFromDir = new ArrayList();
protected void getListFromFile() {
listFromFile = new ArrayList();
BufferedReader is;
try {
is = new BufferedReader(new FileReader(FILENAME));
String line;
while ((line = is.readLine()) != null)
listFromFile.add(line);
} catch (FileNotFoundException e) {
System.err.println("Can't open file list file.");
return;
} catch (IOException e) {
System.err.println("Error reading file list");
return;
}
}
/** Get list of names from the directory */
protected void getListFromDirectory() {
listFromDir = new ArrayList();
String[] l = new java.io.File(".").list();
for (int i=0; i listFromDir.add(l[i]);
}
protected void reportMissingFiles() {
for (int i=0; i if (!listFromDir.contains(listFromFile.get(i)))
System.err.println("File " + listFromFile.get(i) + " missing.");
}
}