This simple code first checks if the Folder/Directory with the desired name exists or not. If there is no such Folder/Directory then the code will create one Folder/Directory with the name defined.
- File theDir = new File("New Folder"); // Defining Directory/Folder Name
- try{
- if (!theDir.exists()){ // Checks that Directory/Folder Doesn't Exists!
- boolean result = theDir.mkdir();
- if(result){
- JOptionPane.showMessageDialog(null, "New Folder created!");}
- }
- }catch(Exception e){
- JOptionPane.showMessageDialog(null, e);
- }
No comments:
Post a Comment