new File("/path/directory").mkdirs();
Here "directory" is the name of the directory you want to create/exist.
Answer from Bozho on Stack Overflow Top answer 1 of 16
630
new File("/path/directory").mkdirs();
Here "directory" is the name of the directory you want to create/exist.
2 of 16
567
After ~7 year, I will update it to better approach which is suggested by Bozho.
File theDir = new File("/path/directory");
if (!theDir.exists()){
theDir.mkdirs();
}
Videos
Create Folders - Java Programming
10:01
How to Create Directory and File Using Files Class in Java | File ...
02:51
How to create a folder in Java (Core Java Interview Question #263) ...
04:25
How to Create Any Folder At Runtime Using Java - YouTube
05:02
How to create a Resource folder in Java with IntelliJ and how to ...
20:01
Unveiling the Java File Handling Technique for Easy Folder Creation ...
Mkyong
mkyong.com › home › java › how to create directory in java
How to create directory in Java - Mkyong.com
July 29, 2020 - In Java, we can use the NIO `Files.createDirectories` to create a directory including all nonexistent parent directories.
ZetCode
zetcode.com › java › createdirectory
Java create directory - learn how to create a directory in Java
The Files.createDirectories creates a new directory; if the parent directories do not exist, they are created as well. The method does not thrown an exception if the directory already exist. ... package com.zetcode; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; ...
Blogger
java-demos.blogspot.com › 2012 › 10 › create-directory-in-java.html
How to create folder in Java — Java Demos
A tiny and easy example to create a directories in Java with mkdir() and mkdirs() methods. import java.io.File; class CreateDirectory { public static void main(String args[]) { // Create a java.io.File object, specify the name of the folder File f=new File("mydir"); // Create directory with ...
Alvin Alexander
alvinalexander.com › java › java-create-directory-directories-file-mkdirs
How to create directories in Java | alvinalexander.com
If you need to create multiple directories at one time, you can use the mkdirs method of the Java File class, as shown in this example:
Oracle
docs.oracle.com › javase › tutorial › essential › io › dirs.html
Creating and Reading Directories (The Java™ Tutorials > Essential Java Classes > Basic I/O)
The first method allows the code to specify a location for the temporary directory and the second method creates a new directory in the default temporary-file directory.
Mccue
javabook.mccue.dev › files › creating_a_folder
Create a Folder - Modern Java
To create a folder, you can use Files.createDirectory. import java.nio.file.Files; import java.nio.file.Path; class Main { void main() throws IOExeption { Path folderPath = Path.of("example1"); Files.createDirectory(folderPath); } } This, like the other methods in Files, might throw an IOException.
Javatpoint
javatpoint.com › how-to-create-a-new-folder-in-java
How to Create a New Folder in Java - Javatpoint
How to Create a New Folder in Java with java tutorial, features, history, variables, object, programs, operators, oops concept, array, string, map, math, methods, examples etc.
Java67
java67.com › 2014 › 02 › how-to-create-file-and-directory-in-java.html
How to Create File and Directory in Java with Example | Java67
Enter file name to be created Abhishek.txt File already exists Don't forget to close Scanner once done, a good practice to prevent resource leaks in Java. Alternatively, you can also use try-with-resources statements from Java 7, which facilitate automatic resource clean-up for you. That not only take care of releasing resources once you are done with that, but also removes coding headache and finally block from above code, making it more concise and readable. That's all about how to create or make files and directories in Java.
TutorialsPoint
tutorialspoint.com › how-to-create-a-directory-in-project-folder-using-java
How to create a directory in project folder using Java?
import java.io.File; import java.util.Scanner; public class CreateDirectory { public static void main(String args[]) { System.out.println("Enter the path to create a directory: "); Scanner sc = new Scanner(System.in); String path = sc.next(); System.out.println("Enter the name of the desired a directory: "); path = path+sc.next(); //Creating a File object File file = new File(path); //Creating the directory boolean bool = file.mkdir(); if(bool){ System.out.println("Directory created successfully"); } else { System.out.println("Sorry couldn’t create specified directory"); } } }
Attacomsian
attacomsian.com › blog › java-create-directory
How to create a directory in Java
December 13, 2019 - You can even use Files.createDirectories() to create multiple nested directories at once. This method creates all nonexistent parent directories first. Here is an example: try { // directory path Path path = Paths.get("./java/jvm/1.8"); // create directory Files.createDirectories(path); }catch (IOException ex) { ex.printStackTrace(); } You can also use the classic Java I/O package (classes in java.io.*) to create a new directory.
OpenGenus
iq.opengenus.org › creating-and-deleting-folders-in-java
Creating and Deleting Folders in Java
February 7, 2020 - File Java class of java.io package represents a file or directory in the system. It contains various methods to perform operations on file/ directory. mkdir() method of file class is used to create a new directory denoted by the abstract pathname.
O'Reilly
oreilly.com › library › view › java-cookbook › 0596001703 › ch10s10.html
Making New Directories - Java Cookbook [Book]
June 21, 2001 - Making New DirectoriesProblemYou need to create a directory. SolutionUse java.io.File’s mkdir( ) or mkdirs( ) method. DiscussionOf the two methods used for creating directories,... - Selection from Java Cookbook [Book]
Author Ian F. Darwin
Published 2001
Pages 888
TutorialsPoint
tutorialspoint.com › how-to-create-a-directory-hierarchy-using-java
How to create a directory hierarchy using Java?
March 12, 2024 - To create a hierarchy of new directories you can using the method mkdirs() of the same class. This method creates the directory with the path represented by the current object, including non-existing parent directories. import java.io.File; import java.util.Scanner; public class CreateDirectory ...