I am trying to write a file using java.io where I am trying to create it in the location "some/path/to/somewhere/then-my-file" . When a file is created, any of the directories in the path may or may not exist. Instead of throwing an IOException because there are no such directories, I would like directories to be created transparently when and when necessary.
Is there a method that will create any directories needed to write a file? I am looking for something in the Java SDK or within an easy library that I can add to the classpath, for example. Apache Commons IO.
PS For clarity, I have already coded a solution that works in a rather narrow way, I am testing it, so I do not need suggestions on how to write the method I'm looking for. I am looking for a method that will be fairly well tested and cross-platform.
Grundlefleck
source share