Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating a sub sub directory  RSS feed

 
michael yue
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I need to create a sub sub directory. That means a directory inside a directory that I also create. Then I have to put a file inside which I also create.
Below are my code. Is it correct ?
String subDirPath = "MANUAL";
File myFile = new File(subDirPath);
if(!myFile.exists())
myFile.mkdir();

String SubDir2 = subDirPath+"/"+subename;
File submyFile = new File(SubDir2);
if(!submyFile.exists())
submyFile.mkdir();

/**** Write to the file ****/
String path2 = "file.txt";
File output2 = new File(SubDir2,path2);
FileWriter out2 = new FileWriter(output2);
out2.write(successtext2);
out2.close();
Thanks a lot.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks good to me. Are you seeing some problems that is causing this not to work, or just curious if there is a better way?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to use of the mkdirs() method, rather than mkdir(). Should be a little simpler.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!