2010-12-13 9 views

उत्तर

38
new File("/path/to/folder").mkdir(); 

आप नेस्टेड फ़ोल्डरों बनाया (यानी रास्ते पर एक से अधिक फ़ोल्डर गायब हो सकता है) चाहते हैं, तो mkdirs() का उपयोग करें। java.io.File देखें।

ध्यान दें कि आगे की स्लैश सामान्य रूप से विंडोज़ पर काम नहीं करती हैं, लेकिन जावा पथ को सामान्य करता है और आगे की पिछली स्लैश में अनुवाद करता है।

+0

यह मेरे लिए काम नहीं कर रहा है क्या कोई मुझे कारण बता सकता है? मैंने इसे पहले ही पोस्ट कर दिया है, लेकिन फिर भी इसे हल करने में सक्षम नहीं हो सकता है http://stackoverflow.com/questions/18940987/creating-a-folder-within-web-server-under-public-html-in-java – Sadanand

+0

उत्तर उपर्युक्त टिप्पणी के लिए - समस्या हल की गई: "/xyz.com/appFolder/" के रूप में पथ देने के बजाय, "घर/XYZ/public_html/appFolder" – Sadanand

3
try{ 
    String strDirectoy ="test"; 
    String strManyDirectories="dir1"+File.Separator+"dir2"+File.Separator+"dir3"; 

    // Create one directory 
    boolean success = (new File(strDirectoy)).mkdir(); 
    if (success) { 
     System.out.println("Directory: " + strDirectoy + " created"); 
    }  


    // Create multiple directories 
    success = (new File(strManyDirectories)).mkdirs(); 
    if (success) { 
     System.out.println("Directories: " + strManyDirectories + " created"); 
    } 

    }catch (Exception e){//Catch exception if any 
     System.err.println("Error: " + e.getMessage()); 
    } 
1

उपयोग File.mkdir() (http://download.oracle.com/javase/1.4.2/docs/api/java/io/File.html#mkdir())

-2
try{  
    int a,b; 
     a=mk.dir(); 
     b=newfile("\n new.java()); 
    } 
+1

के रूप में पूर्ण पथ देना चाहिए, कृपया कम से कम 'पकड़' ब्लॉक कुछ विवरण जोड़ें। –

संबंधित मुद्दे