|
Java™ by example!
|
|
|
How do I create and remove a directory?
 import java.io.*; public class creDelDir { public static void main(String args[]) { //Creates the directory named by this abstract pathname. File f1 = new File("dir1"); f1.mkdir(); /* Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. */ File f2 = new File("dir1/dir2/dir3"); f2.mkdirs(); /* Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a directory, then the directory must be empty in order to be deleted.*/ f1.delete(); f2.delete(); } }
|
f1.delete does not delete dir1, because it contains subdirectories. After execution File System will have 'dir1/dir2' directory structure.
Further Information
Author of answer: Kishore Koya
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|