Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Java Programming Code Examples

Java > Core Java Code Examples

Check for Files

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
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."); } }