import java.io.*; class CreateDirectory{ static void createDirectory(String location, String name)throws Exception{ File file = new File(location +"\\" + name); if (!file.exists()) { if (file.mkdir()) { System.out.println("Directory is created!"); } else { System.out.println("Failed to create directory!"); } } } public static void main(String args[])throws Exception{ BufferedReader br; br = new BufferedReader(new InputStreamReader(System.in)); String name, location; System.out.println("Enter Directory Name"); name = br.readLine(); System.out.print("Enter the Location "); System.out.println("where the directory to be created"); location = br.readLine(); createDirectory(location, name); } }
Output
Enter
Directory Name
new31
Enter
the Location where the directory to be created
C:\Users\Downloads
Directory
is created!
No comments:
Post a Comment