I'm confused by the FileUtils.openOutputStream(File) method in commons-io.
The javadoc for this method says this: "The file will be created if it does not
exist." That doesn't seem ambiguous. However, I noticed while stepping
through new code that is calling this for a path that doesn't exist yet, I find
that the parent directory has been created, but it's not creating the file.
In fact, it's even getting this exception:
Caused by: java.io.FileNotFoundException: .... (The system cannot find the path
specified)
at org.apache.commons.io.FileUtils.openOutputStream(FileUtils.java:367)
The implementation of this method makes it pretty clear:
----------------------
public static FileOutputStream openOutputStream(File file, boolean append)
throws IOException {
if (file.exists()) {
if (file.isDirectory()) {
throw new IOException("File '" + file + "' exists but is a
directory");
}
if (file.canWrite() == false) {
throw new IOException("File '" + file + "' cannot be written
to");
}
} else {
File parent = file.getParentFile();
if (parent != null) {
if (!parent.mkdirs() && !parent.isDirectory()) {
throw new IOException("Directory '" + parent + "' could not
be created");
}
}
}
return new FileOutputStream(file, append);
}
-----------------
The javadoc for the FileOutputStream constructor states that it will throw that
exception if the file doesn't exist.
What's going on here?
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]