We must read other File operations like - create, copy, move, rename, delete, append, hide/unHide, creation/lastModified/lastAccessed date, compare, size, Read only and writable.
java.io.File's exists() method can to find whether File exists or not
Method returns true - if File exists
Method returns false - if File doesn't exists
Program to find File exists or not - in java file IO >
import java.io.File;
/** JavaMadeSoEasy.com */
public class FileExists {
public static void main(String... args) {
String fileName = "c:/myFile.txt";
File file = new File(fileName);
boolean fileExists = file.exists();
if(fileExists)
System.out.println(fileName +" exists");
else
System.out.println(fileName +" doesn't exists");
}
}
/* OUTPUT
c:/myFile.txt exists
*/
|
RELATED LINKS>
Create File using createNewFile() method in java file IO
Copy a file in java 2 in ways - use org.apache.commons.io.FileUtils's copyDirectory(sourceDirectory, destDirectory)
Program on How to hide and unHide file or Directory in java 7 using java.nio.file
Program to Create Directory - Single and multiple (i.e. parent and child directories) in java file IO
Copy a Directory
Traverse a Directory (all sub-directories and files) in 2 ways
Labels:
Core Java
File IO/File handling