CreateDirectory.java
-------------------------------------------------------------------------------------------------------
import java.io.*;
class CreateDirectory
{
public static void main(String args[])
{
try{
String myfolder ="c:/test";
String mySubFolder1="c:/test/dir1";
String mySubFolder2="c:/test/dir2";
String mySubFolder3="c:/test/dir3/dir4/dir5";
// Create folder test under c:
//return true if created successfully
boolean success = (new File(myfolder)).mkdir();
//create a file inside that folder,returns true if successful
success = new File("c:/test/myfile.txt").createNewFile();
// Create multiple folders inside test
success = (new File(mySubFolder1)).mkdir();
success = (new File(mySubFolder2)).mkdir();
success = (new File(mySubFolder3)).mkdirs();
System.out.println("Successfull");
}catch (Exception e){System.err.println("Error: " + e.getMessage());}
}//main
}//class
-----------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
import java.io.*;
class CreateDirectory
{
public static void main(String args[])
{
try{
String myfolder ="c:/test";
String mySubFolder1="c:/test/dir1";
String mySubFolder2="c:/test/dir2";
String mySubFolder3="c:/test/dir3/dir4/dir5";
// Create folder test under c:
//return true if created successfully
boolean success = (new File(myfolder)).mkdir();
//create a file inside that folder,returns true if successful
success = new File("c:/test/myfile.txt").createNewFile();
// Create multiple folders inside test
success = (new File(mySubFolder1)).mkdir();
success = (new File(mySubFolder2)).mkdir();
success = (new File(mySubFolder3)).mkdirs();
System.out.println("Successfull");
}catch (Exception e){System.err.println("Error: " + e.getMessage());}
}//main
}//class
-----------------------------------------------------------------------------------------------------------
No comments:
Post a Comment