commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jamie Bisotti" <jbiso...@gmail.com>
Subject Re: [IO] writeStringToFile( File, String, String ), when File does not exist
Date Wed, 07 Jun 2006 19:39:25 GMT
On 6/7/06, Cimballi <cimballi@cimballi.net> wrote:
>
> The directory have to exists, the javadoc only talks about the file.
> Form source :
>
> public static void writeStringToFile(File file,
>             String data, String encoding) throws IOException {
>         OutputStream out = new FileOutputStream(file);
>         try {
>             IOUtils.write(data, out, encoding);
>         } finally {
>             IOUtils.closeQuietly(out);
>         }
>     }
>
> Cimballi
>
> > So, is there anyone on this list that can/will provide a definitive
> answer
> > to my original question?  Should I be asking it elsewhere?  Thanks.
> >
> > --
> > Jamie Bisotti
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
As I mentioned in my original post...The JavaDoc for writeStringToFile()
says: "Writes a String to a file creating the file if it does not exist."
That seems to imply that directories would be created, if need be; however,
that is not happening.  Is this a bug?  Or does the documentation just need
to be clarified?

It does not say anything about directories having to exist; it says the file
will be created if it does not exist. Taking the JavaDoc comment as
literally as possible, if I have an existing directory structure like this:

/parentDirectory

and I call,

FileUtils.writeStringToFile( new File(
"/parentDirectory/childDirectory/grandChildDirectory", "myFile.txt" ), "Foo
bar", "UTF-8" );

I would think /parentDirectory/childDirectory/grandChildDirectory/myFile.txt
would get created.  So, my original question still stands: Is this a bug or
an incomplete comment, in need of clarification?

Thanks.

-- 
Jamie Bisotti

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message