Thread: String saving

Results 1 to 4 of 4
  1. #1 String saving 
    Registered Member iWho's Avatar
    Join Date
    Mar 2010
    Posts
    19
    Thanks given
    0
    Thanks received
    3
    Rep Power
    1
    Okay, so I'm trying to make the following method save a string, but if called again it will just add the new string.. At the moment it overrides the old File.. so could you help me out?
    Code:
    	public static void Write(String filename, String str){
    		BufferedWriter bufferedWriter = null;
    		try {
    			bufferedWriter = new BufferedWriter(new FileWriter(filename));
    			bufferedWriter.write(""+str);
    			bufferedWriter.newLine();
    			bufferedWriter.close();
    		} catch (FileNotFoundException ex) {
    			ex.printStackTrace();
    		} catch (IOException ex) {
    			ex.printStackTrace();
    		}
    	}
    Reply With Quote  
     

  2. #2  
    Member String saving Market Banned


    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    35
    Posts
    12,574
    Thanks given
    199
    Thanks received
    7,106
    Rep Power
    5000
    Use randomAccessFile and set the filepointer to the end of the file.

    Attached imageAttached image
    Reply With Quote  
     

  3. #3  
    Registered Member iWho's Avatar
    Join Date
    Mar 2010
    Posts
    19
    Thanks given
    0
    Thanks received
    3
    Rep Power
    1
    Quote Originally Posted by Duke Lukem View Post
    Use randomAccessFile and set the filepointer to the end of the file.
    Could you help me out a bit more with that? (c)
    Reply With Quote  
     

  4. #4  
    Programmer, Contributor, RM and Veteran




    Join Date
    Mar 2007
    Posts
    5,147
    Thanks given
    2,656
    Thanks received
    3,731
    Rep Power
    5000
    http://java.sun.com/j2se/1.4.2/docs/...,%20boolean%29

    basically, do:

    Code:
    new FileWriter(filename, true)
    .
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

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