FileUtils from apache commons is a pretty good way to achieve this in a single line.
This will create parent folders if do not exist and create a file if not exists and throw a exception if file object is a directory or cannot be written to. This is equivalent to:
All the above operations will throw an exception if the current user is not permitted to do the operation.
|