Click here to watch in Youtube :
Click the below Image to Enlarge
Java Tutorial : Java IO (Java File - How to create the directory) |
import java.io.File;
public class FileDemo1
{
public static void main(String[] args)
{
File file = new File("D:/work/java");
/*
* Creates the directory named by this abstract
* pathname.
*
* Returns: true if and only if the directory was
* created; false otherwise
*/
boolean dirCreated = file.mkdir();
System.out.println(file.getAbsolutePath()
+ " directory Created? = " + dirCreated);
}
}
OutputD:\work\java directory Created? = true
import java.io.File;
public class FileDemo2
{
public static void main(String[] args)
{
File file = new File("D:/work/java/arraylist/src");
/*
* Creates the directory named by this abstract
* pathname, including any necessary but nonexistent
* parent directories.
*
* Returns: true if and only if the directory was
* created, along with all necessary parent
* directories; false otherwise
*/
boolean dirCreated = file.mkdirs();
System.out.println(file.getAbsolutePath()
+ " directory Created ? = " + dirCreated);
}
}
D:\work\java\arraylist\src directory Created ? = true
No comments:
Post a Comment