commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jamie Bisotti" <jbiso...@gmail.com>
Subject [IO] writeStringToFile( File, String, String ), when File does not exist
Date Mon, 05 Jun 2006 18:29:55 GMT
Assuming 'parentDirectory' exists but 'myFile.txt' does not,

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

works just fine; it creates 'myFile.txt' in 'parentDirectory'.  However, if
'childDirectory' does not exist,

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

throws a FileNotFoundException because 'myFile.txt' cannot be opened in the
non-existent 'childDirectory'.  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?

Thanks.

-- 
Jamie Bisotti

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