This discussion is archived
9 Replies Latest reply: Mar 3, 2010 9:24 PM by EJP RSS

Check file exists

843789 Newbie
Currently Being Moderated
This is my program for checking .txt files from current folder to another folder. I have a list of files in FolderB that i want to check if they exists in FolderA. The problem is that i cant get the checkFile() method to check each file from the arraylist one at a time. How can i do that??
public class FileList
{


    public static void checkFile() {
        
 
   try {
       
        File cFile = new File("C:/FolderA");
        boolean exists = cFile.exists();

        if (!exists) {
            //It returns false if File or directory does not exist
            System.out.println("The file  does not exist :" + exists);
            //moveFile();

        } else {
            // It returns true if File or directory exists
            System.out.println("The file  does exist : " + exists);

        }
    } catch (Exception ex){
         System.out.println("Exception in checkFile method::" +ex);
    }
    }
   public static void main(String args[]){
   File file = new File("C:/FolderB");
   File[] files = file.listFiles();
   for (int x = 0; x < files.length; x++)
   {
   System.out.println(files[x].toString());
   checkFile(files[x]);

   }
 }
}
Thanks

complete newbie