You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Sebb (JIRA)" <ji...@apache.org> on 2015/03/14 02:39:39 UTC
[jira] [Updated] (IO-472) FileUtils.openOutputStream doesn't create
file if it doesn't exist
[ https://issues.apache.org/jira/browse/IO-472?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Sebb updated IO-472:
--------------------
Description:
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:
{code:java}
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);
}
{code}
If it doesn't exist, it will just try to create a FileOutputStream, which throws a FileNotFoundException.
was:
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.
> 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:
> {code:java}
> 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);
> }
> {code}
> 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)