Methods and Results
Description:
1 folder
(. file.getParentFile () exists () ) if {// determines whether there is a folder
System.out.println ( "folder exists !!");
} the else {
System.out.println ( "folder does not exist! ! ");
file.getParentFile () mkdirs ();. // mkdir (); create a directory
}
2 file
if (file.exists ()) {// file exists determines
System.out.println ( "present !!");
} the else {
System.out.println ( "absent !!");
the try {
file.createNewFile ();
} the catch (IOException E) {
System.out.println ( "creation failed");
e.printStackTrace ();
}
}
3 judgment file attributes
isDirectory () to check whether an object is a folder.
@GF