This program will make a directory called 'MyDirectory' in the C:\ drive.
Code :import java.io.File; public class MakeDir { public static void main(String[] args) { String path = "C:\\MyDirectory"; File file1 = new File(path); file1.mkdir(); } }
Printable View
This program will make a directory called 'MyDirectory' in the C:\ drive.
Code :import java.io.File; public class MakeDir { public static void main(String[] args) { String path = "C:\\MyDirectory"; File file1 = new File(path); file1.mkdir(); } }
a common mistake here is that you don't check the boolean value return from the mkdir() method. It returns true if the operation succeeded, false if the user doesn't have permission or anything else happened.
Spring 3
tried this, and it doesn't work; just prints out false. Use mkdirs().