File Create an empty directory, create a multi-level directory, delete a directory

package seday03;

import java.io.File;

/ **
* Create an empty directory,
* @author xingsir
* /
public class MkDirDemo {

static void main public (String [] args) {
/ *
* In the current directory, create a file called: demo directory
* Relative path "./" can not write, the default is to start in the current directory
* /
File File = File new new ( "the Test");
IF (File.Exists ()!) {
file.mkdir ();
System.out.println ( "directory successfully created");
} the else {
System.out.println ( "already exists directory ");
}
}

}

//==============================================================================

package seday03;

import java.io.File;

/ **
* Create a multi-level directory
* @author xingsir
* /
public class MkDirsDemo {

public static void main (String [] args) {
/ *
* created in the current directory: A / B / C / D / E / F.
* /
File the dir = new new File ( "A / B / C / D / E / F ");
(! dir.exists () IF) {
// create the current directory is the parent directory does not exist will together establish
dir.mkdirs ();
System.out.println (" directory has been created ")!;
the else {}
System.out.println ( "directory already exists!");
}
}

}

//=========================================================================

package seday03;

import java.io.File;

/ **
* Remove a directory
* @author xingsir
* /
public class DeleteFileDemo {

static void main public (String [] args) {
File dir = new new File ( "the Test");
IF (dir.exists ()) {
/ *
* Delete the directory on the premise that this directory is an empty directory
* /
dir.delete ();
System.out.println ( "deleted directory");
} the else {
System.out.println ( "directory does not exist");
}
}

}

 

Guess you like

Origin www.cnblogs.com/xingsir/p/11984188.html