Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a folder in Java?

How can I create an empty folder in Java?

like image 893
user364669 Avatar asked Jun 11 '10 15:06

user364669


People also ask

How do you create a directory in Java?

In Java, the mkdir() function is used to create a new directory. This method takes the abstract pathname as a parameter and is defined in the Java File class. mkdir() returns true if the directory is created successfully; else, it returns false​.

How do you create a folder in coding?

Keyboard Shortcut: ctrl+alt+N to create new files & ctrl+alt+shift+N to create new folders. (you can override these shortcuts). Press ctrl+shift+p to open command panel and type Create File or Create Folder . Right click on Explorer Window and click Create File or Create Folder .

What is directory in Java?

A file system structure containing files and other directories is called directories in java, which are being operated by the static methods in the java. nio. file. files class along with other types of files, and a new directory is created in java using Files.

How do you make an empty folder in Java?

You can create folder using the following Java code: File dir = new File("nameoffolder"); dir. mkdir(); By executing above you will have folder 'nameoffolder' in current folder.


1 Answers

File f = new File("C:\\TEST"); try{     if(f.mkdir()) {          System.out.println("Directory Created");     } else {         System.out.println("Directory is not created");     } } catch(Exception e){     e.printStackTrace(); }  
like image 51
Luc M Avatar answered Oct 06 '22 21:10

Luc M