[
https://issues.apache.org/jira/browse/IO-472?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14360872#comment-14360872
]
David M. Karr commented on IO-472:
----------------------------------
The situation might not be exactly as I described. As I see in the
FileOutputStream javadoc, it implies that it will create the file if it doesn't
exist, so this should have worked.
When I run this for my test case, I get the following exception:
java.io.IOException: The system cannot find the path specified
That's not quite a "FileNotFoundException". When I google for this, it appears
to refer to the supposed 260 character limit for file paths on Windows.
Curiously, although the path I'm creating is quite long, it's still short of
260 by 30 or more characters.
I even added code before the call to "openOutputStream" that attempts to create
the file if it doesn't exist, and that's failing with the same error, so I
would conclude that this isn't a particular problem with FileUtils.
> FileUtils.openOutputStream doesn't create file if it doesn't exist
> ------------------------------------------------------------------
>
> Key: IO-472
> URL: https://issues.apache.org/jira/browse/IO-472
> Project: Commons IO
> Issue Type: Bug
> Components: Utilities
> Affects Versions: 2.4
> Reporter: David M. Karr
>
> The javadoc for this method has a pretty unambiguous statement: "The file
> will be created if it does not exist." However, this isn't happening. The
> code is pretty clear on this:
> ----------------- 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);
> }
> -----------------
> If it doesn't exist, it will just try to create a FileOutputStream, which
> throws a FileNotFoundException.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)