Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

append string into File

Thread view: 
Marcelo - 19 Oct 2005 10:02 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.