Monday, October 31, 2011

Checking a file/directory present or not

The following code 'll return boolean values,true if the file/directory is present,false if the file/directory is not present.
  1. public boolean isFileOrDirectoryPresent(String fileOrDirName){
  2.   File file = new File(fileOrDirName);
  3.   if (!file.exists()){
  4.     System.out.println("File/Directory doesn't exist");
  5.     return false;
  6.   }
  7.   else {
  8.     System.out.println("File/Directory exists");
  9.     return true;
  10.   }
  11. }

No comments:

Post a Comment