commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lazarte, Ivan" <>
Subject RE: [IO] writeStringToFile( File, String, String ), when File does not exist
Date Tue, 06 Jun 2006 07:40:27 GMT
Personal pet peeve, I would love it if IO lib trusted the developer a bit more.  It trusts
you like 90% already, but i'd prefer 100 :)  A wrapper I always write for any file lib is
a "writeFileNoComplain" which takes any file/directory combo and writes it completely making
sure each part is unix friendly. 
This allows me to make up very sophisticated file backup/logging/caching structures with ease,
where I can just pass in locations like "/data/<class_name>/<product>/<date|timestamp>/<arguments_concatenated>.cache"
 and let the file lib do the work of saving it..


From: Jamie Bisotti []
Sent: Mon 6/5/2006 1:29 PM
To: Jakarta Commons Users List
Subject: [IO] writeStringToFile( File, String, String ), when File does not exist

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


Jamie Bisotti

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