Results 1 to 3 of 3

Thread: Writing to a text file *Resolved*

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194

    Writing to a text file *Resolved*

    This section of code writes the contents of a variable to a text file:

    Code:
       
    
    			//writes contents of TADisplay to a text file 
    			try {
    
    			File  File2  =  new   File("applications.txt");
    
    			FileOutputStream  outpFile2  =  new  FileOutputStream(File2);
    			DataOutputStream  outp  =  new  DataOutputStream(outpFile2);
    
    			{
    				outp.writeUTF(s);	}	
    
    				outp.close();
    
    			}
    		
    			catch (IOException  ex) {
    				System.out.println(ex);
    				}
    that works fine - but what i wish to do now is next time the application runs, save the next contents of the variable AS WELL as the one that is already in the text file. At the moment it overwrites it.

    Any suggestions?
    Last edited by mbonfyre; Apr 13th, 2003 at 10:31 AM.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Code:
    FileOutputStream  outpFile2  =  new  FileOutputStream(File2);
    Change this line to...
    Code:
    FileOutputStream  outpFile2  =  new  FileOutputStream("applications.txt", true);
    That will append the new data to the end of the file.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194
    thanks for that - it was just the job!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width