append string into File  
Author Message
Marcelo





PostPosted: 2005-10-19 17:03:00 Top

java-programmer, append string into File Hi,

I am having a big trouble while saving information into a file. I would
like append some information into file. However, each time that I try to
do this, the information of the file is replaced by the new information.

What is wrong with my routine?


File simFile = new File("simulations.txt");
//System.out.println("simulations: "+simFile.getAbsolutePath());
try{
if(simFile == null)
throw new IOException();

BufferedWriter output = new BufferedWriter(new FileWriter(simFile));

String text = simObj.getInfo();
output.append(text);
//output.newLine();
closeFile(output);
}catch(IOException e){
System.err.println("Cannot save Simulation into file");
}

thanks very much,


Marcelo
 
Andrew Thompson





PostPosted: 2005-10-19 17:55:00 Top

java-programmer >> append string into File Marcelo wrote:

> What is wrong with my routine?

Not enough research in the JavaDocs?

> File simFile = new File("simulations.txt");
> //System.out.println("simulations: "+simFile.getAbsolutePath());
> try{
> if(simFile == null)
> throw new IOException();
>
> BufferedWriter output = new BufferedWriter(new
> FileWriter(simFile));

<http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileWriter.html#FileWriter(java.io.File,%20boolean)>
 
Roedy Green





PostPosted: 2005-10-19 18:07:00 Top

java-programmer >> append string into File On Wed, 19 Oct 2005 11:02:51 +0200, Marcelo <email***@***.com> wrote
or quoted :

>I am having a big trouble while saving information into a file. I would
>like append some information into file. However, each time that I try to
>do this, the information of the file is replaced by the new information.

See http://mindprod.com/applets/fileio.html

Ask it to generate you some code to handle your problem.

The code you wrote is SUPPOSED to overwrite.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
 
Marcelo





PostPosted: 2005-10-19 23:31:00 Top

java-programmer >> append string into File Andrew Thompson wrote:
> Marcelo wrote:
>
>> What is wrong with my routine?
>
>
> Not enough research in the JavaDocs?
>
>> File simFile = new File("simulations.txt");
>> //System.out.println("simulations: "+simFile.getAbsolutePath());
>> try{
>> if(simFile == null)
>> throw new IOException();
>> BufferedWriter output = new BufferedWriter(new
>> FileWriter(simFile));
>
>
> <http://java.sun.com/j2se/1.5.0/docs/api/java/io/FileWriter.html#FileWriter(java.io.File,%20boolean)>
>
thank you very much,
next time I'll do a little bit more of research
thanks

Marcelo
 
 
Andrew Thompson





PostPosted: 2005-10-19 23:41:00 Top

java-programmer >> append string into File Marcelo wrote:

> next time I'll do a little bit more of research

Excellent! Next time you will be able to *tell* me
the answer. :-)