A: File class to create a directory
to create the directory is used to when a new data when necessary to save certain file or picture to the local time,
you need a folder filled, this time in order to preserve success, with or without prior creation a folder, it
will use a judge sentences judgment we need to save the directory path exists, if there is to be saved directly, as
if to create a directory that does not exist.
A test case:
Test4 {class public public static void main (String [] args) { File the dir = new new File:; ( "D / Test") (! dir.exists ()) {// IF determines whether a directory exists dir.mkdir () ; } } }
Create a perfect success, and now we are creating a parent directory, then I now need a multi-directory, I
then try the path into multiple layers, there are two cases Oh, the first one is, if you have With the catalog of the first layer,
then create a directory on the inside, the second does not exist, first create two directories.
The first:
You can create a successful, two-story directory, or a directory is actually created it, all can successfully created.
static void main public (String [] args) { a Date datetime new new = a Date (); File the dir = new new File ( "D: / Test / test1"); IF (! dir.exists ()) {// determines whether a directory present dir.mkdir (); System.out.println ( "performed" datetime +); } }
The second: In the D drive is not present in the directory, you need to create two-story directory
The dir = new new File File:; ( "D / test1 / test2") (! Dir.exists ()) {// IF determines whether a directory exists dir.mkdir (); System.out.println ( "- .. performed a "); }
Code has been executed did not create the required directory to the second floor. After testing some computers write is no problem, the normal create, how you create can not do it? Calls another
Test4 {class public public static void main (String [] args) { a Date datetime new new = a Date (); File the dir = new new File ( "D: / test1 / test2"); IF (! dir.exists ()) {/ / Analyzing directory exists //dir.mkdir (); dir.mkdirs (); // call to the required directory multilayer mkdirs System.out.println ( "performed" datetime +); } }
A two-story directories are created successful.
Original: https: //blog.csdn.net/Yangll29/article/details/90633064