You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Kenneth Love <kl...@tax.ok.gov> on 2006/04/06 21:09:09 UTC

Looking for a string to file appending function

Hello,

I'm looking for a function similar to the following:

org.apache.commons.io.FileUtils.writeStringToFile(file, msg, encoding)

I need to append to an already existing file.  Unfortunately, the
function call above overwrites the contents of the file.

Does a function with the functionality I need already exist somewhere
in the Jakarta Commons libraries?

How easy would it be to overload writeStringToFile() so that it has a
fourth parameter allowing appending to a file instead of overwriting it?

                                                 Sincerely,
                                                 Kenneth Love


Kenneth Love                       My opinions are my own and no
Oklahoma Tax Commission            relation to reality should
Integrated Tax System              be inferred.
klove@tax.ok.gov 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Looking for a string to file appending function

Posted by Stephen Colebourne <sc...@btopenworld.com>.
Kenneth Love wrote:
> org.apache.commons.io.FileUtils.writeStringToFile(file, msg, encoding)
> 
> I need to append to an already existing file.  Unfortunately, the
> function call above overwrites the contents of the file.
> 
> Does a function with the functionality I need already exist somewhere
> in the Jakarta Commons libraries?

At present there is no such method in [io] or any other commons library. 
I recommend that you open a bugzilla enhancemnet request (following the 
instructions on the website). If possible, you could write the code and 
unit test and add them to the call.

BTW, we try to avoid boolean flag parameters, as they represent a bit of 
a code smell. Thus we would favour an appendStringToFile() method

Stephen


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Looking for a string to file appending function

Posted by Mark A Fortner <ph...@yahoo.com>.
Yeah.  Can't help you there.  Most things require a
little bit of work - and documentation is one of them.
;-) The FileWriter super class has an encoding
parameter you can set.  

If you're using an IDE most of them have code lookup
features that will help you explore the API a little
easier.  And they also autogenerate comment stubs.

Mark

--- Kenneth Love <kl...@tax.ok.gov> wrote:

> 
> That would work except for three things:
> 
> A) I have to write/document/maintain the function.
> B) There is no encoding parameter.
> C) Garbage collection hints are missing.
> 
> Granted, if I wrote it myself, reasons B and C would
> be handled.
> 
> Mostly, I was just wanting to be lazy and use
> someone else's already
> tested/debugged code.  :-)
> 
> I've been really impressed with the Commons IO
> library.  There are so
> many methods/classes/interfaces/etc. that are "the
> way things ought to
> be".  The only lament I have about this library is
> that I was programming
> in Java for 8 months before I heard about it.
> 
> Kenneth
> 
> At 02:37 PM 4/6/2006, you wrote:
> >Kenneth,
> >You might want to try this: 
>
>http://javaalmanac.com/egs/java.io/AppendToFile.html
> >
> >HTH,
> >Mark
> >
> >Kenneth Love wrote:
> >>
> >>Hello,
> >>
> >>I'm looking for a function similar to the
> following:
> >>
>
>>org.apache.commons.io.FileUtils.writeStringToFile(file,
> msg, encoding)
> >>
> >>I need to append to an already existing file. 
> Unfortunately, the
> >>function call above overwrites the contents of the
> file.
> >>
> >>Does a function with the functionality I need
> already exist somewhere
> >>in the Jakarta Commons libraries?
> >>
> >>How easy would it be to overload
> writeStringToFile() so that it has a
> >>fourth parameter allowing appending to a file
> instead of overwriting it?
> >>
> >>                                                
> Sincerely,
> >>                                                
> Kenneth Love
> >>
> >>
> >>Kenneth Love                       My opinions are
> my own and no
> >>Oklahoma Tax Commission            relation to
> reality should
> >>Integrated Tax System              be inferred.
> >>klove@tax.ok.gov
> >>
> >>
>
>>---------------------------------------------------------------------
> >>To unsubscribe, e-mail:
> commons-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> >>
> >
> >
>
>---------------------------------------------------------------------
> >To unsubscribe, e-mail:
> commons-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> 
> Kenneth Love                       My opinions are
> my own and no
> Oklahoma Tax Commission            relation to
> reality should
> Integrated Tax System              be inferred.
> klove@tax.ok.gov 
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Looking for a string to file appending function

Posted by Kenneth Love <kl...@tax.ok.gov>.
That would work except for three things:

A) I have to write/document/maintain the function.
B) There is no encoding parameter.
C) Garbage collection hints are missing.

Granted, if I wrote it myself, reasons B and C would be handled.

Mostly, I was just wanting to be lazy and use someone else's already
tested/debugged code.  :-)

I've been really impressed with the Commons IO library.  There are so
many methods/classes/interfaces/etc. that are "the way things ought to
be".  The only lament I have about this library is that I was programming
in Java for 8 months before I heard about it.

Kenneth

At 02:37 PM 4/6/2006, you wrote:
>Kenneth,
>You might want to try this: 
>http://javaalmanac.com/egs/java.io/AppendToFile.html
>
>HTH,
>Mark
>
>Kenneth Love wrote:
>>
>>Hello,
>>
>>I'm looking for a function similar to the following:
>>
>>org.apache.commons.io.FileUtils.writeStringToFile(file, msg, encoding)
>>
>>I need to append to an already existing file.  Unfortunately, the
>>function call above overwrites the contents of the file.
>>
>>Does a function with the functionality I need already exist somewhere
>>in the Jakarta Commons libraries?
>>
>>How easy would it be to overload writeStringToFile() so that it has a
>>fourth parameter allowing appending to a file instead of overwriting it?
>>
>>                                                 Sincerely,
>>                                                 Kenneth Love
>>
>>
>>Kenneth Love                       My opinions are my own and no
>>Oklahoma Tax Commission            relation to reality should
>>Integrated Tax System              be inferred.
>>klove@tax.ok.gov
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org

Kenneth Love                       My opinions are my own and no
Oklahoma Tax Commission            relation to reality should
Integrated Tax System              be inferred.
klove@tax.ok.gov 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Looking for a string to file appending function

Posted by Mark Fortner <ph...@yahoo.com>.
Kenneth,
You might want to try this: 
http://javaalmanac.com/egs/java.io/AppendToFile.html

HTH,
Mark

Kenneth Love wrote:
>
> Hello,
>
> I'm looking for a function similar to the following:
>
> org.apache.commons.io.FileUtils.writeStringToFile(file, msg, encoding)
>
> I need to append to an already existing file.  Unfortunately, the
> function call above overwrites the contents of the file.
>
> Does a function with the functionality I need already exist somewhere
> in the Jakarta Commons libraries?
>
> How easy would it be to overload writeStringToFile() so that it has a
> fourth parameter allowing appending to a file instead of overwriting it?
>
>                                                 Sincerely,
>                                                 Kenneth Love
>
>
> Kenneth Love                       My opinions are my own and no
> Oklahoma Tax Commission            relation to reality should
> Integrated Tax System              be inferred.
> klove@tax.ok.gov
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org