Assume final String fname = "/dir1/dir2/fname.ext". I do not wish to parse the string recursively in order to create the directories if they do not exist, and only then write to a file. I wish to use the given string, fname, for creating the directories and file if each of which does not exist.
-
1Perfect, now we know what you like to do... what have you tried so far?home– home2012-07-08 07:44:12 +00:00Commented Jul 8, 2012 at 7:44
-
Duplicate:stackoverflow.com/questions/6142901/…Cratylus– Cratylus2012-07-08 07:46:15 +00:00Commented Jul 8, 2012 at 7:46
Add a comment
|
2 Answers
This is the code you are looking for:
File myFile = new File("/dir1/dir2/fname.ext");
myFile.getParentFile().mkdirs();
// do your writing being sure the parent directories exist.
2 Comments
Mr.
Please correct to
myFile.getParentFile().mkdirs() so I could mark your post as an answer; and... thank you.Boris Strandjev
@MrRoth I think it was long corrected before you post your comment.