In java, I need to write a string into a new file, like 'c:\test\upload\myfile.txt', if the 'upload' folder is not existing, it will automatically create it. how to do it ? Apache Commons IO has this API ?
In addition to the accepted answer, since the question also mentioned the library Apache Common IO, I report in the following a solution by using this nice library:
File file = new File("... the directory path ...");
FileUtils.forceMkdir(file);
This solution uses the class FileUtils
, from package org.apache.commons.io
and the method forceMkdir
, that "Makes a directory, including any necessary but nonexistent parent directories".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With