Create whole path automatically when writing to a new file

Posted by Bernhard V on Stack Overflow See other posts from Stack Overflow or by Bernhard V
Published on 2010-05-14T11:50:07Z Indexed on 2010/05/14 11:54 UTC
Read the original article Hit count: 193

Filed under:
|
|
|

Hi,

I want to write a new file with the Java FileWriter. I use it like this:

FileWriter newJsp = new FileWriter("C:\\user\Desktop\dir1\dir2\filename.txt");

Now the dir1 and dir2 currently don't exist. I want Java to create them automatically if they aren't already there. Actually Java should set up the whole file path if not already existing.

How can I achieve this?

© Stack Overflow or respective owner

Related posts about java

Related posts about filewriter