Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a new folder in java

 
William Ross
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I create a new folder on my local drive through a Java program? Say for example I wanted C:\test to appear on my C drive after running a program. Thank you.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's just a single directory use File.mkdir().
If you want to ensure that all parent directories are created as well use File.mkdirs().
See the API for more details.
 
William Ross
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea sorry, I should got googled more first. Got it now:

File newFolder = new File(absolute path name);
newFolder.mkdirs();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic