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 - 19 Oct 2005 10:54 GMT
> What is wrong with my routine?
Not enough research in the JavaDocs?
> File simFile = new File("simulations.txt");
> //System.out.println("simulations: "+simFile.getAbsolutePath());
[quoted text clipped - 4 lines]
> 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)>
Marcelo - 19 Oct 2005 16:31 GMT
>> What is wrong with my routine?
>
[quoted text clipped - 9 lines]
>
> <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 - 19 Oct 2005 16:41 GMT
> next time I'll do a little bit more of research
Excellent! Next time you will be able to *tell* me
the answer. :-)
Roedy Green - 19 Oct 2005 11:07 GMT
>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.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.