Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Nov 2010

    Append string on a file

    Hi everyone, Does anyone know how to append a string on an existing xml or text file inside my images folder(fileconn.dir.photos)? I know how to modify but every time I Write the file it replaces it. All I need is to append stuffs into my file. I really need help. By the way, I'm using Netbeans 6.9.1 Java. Thanks
    Last edited by binsint; 2011-01-07 at 14:30.

  2. #2
    Regular Contributor
    Join Date
    Nov 2010

    Re: Append string on a file

    you can use this code when u Create FileConnection

    // this void when u call it u sent The path Which is it "fileconn.dir.photos" & Send The File Name U want 
    // U can Change the File name As U want to not replace the other
    private void saveFile(String path, String name) {
            try {
                String url = path + name;
                // here i am getting the text from TextBox called txt 
                byte data[] = txt.getBytes();
                FileConnection fconn = (FileConnection)Connector.open(url, Connector.READ_WRITE);
                if (!fconn.exists()) {
                OutputStream ops = fconn.openOutputStream();
            catch (IOException ioe) {
                System.out.println("IOException: "+ioe.getMessage());
            catch (SecurityException se) {
                System.out.println("Security exception:" + se.getMessage());
    U can Change The name u send to This void which well change the name of txt file Saved

    hope it work with u

    inform me if not
    Let The Impossible Happen!!!

  3. #3
    Super Contributor
    Join Date
    Mar 2005

    Re: Append string on a file

    - not a chance. this will replace the existing content.

    - appending to an xml file is likely to cause problems since you would need to insert your text inside an existing tag.

    - you need to append to the file, so, according to petrib :
    Quote Originally Posted by petrib View Post
    Use fileSize() to get the size of the file.

    Then when you want to write to it, use openOutputStream() with an argument that sets the offset to the end of the file (size of the file) and start writing.

    If you set the parameter (offset) to the maximum value of a long, then you don't need to get the size/length of the file. The SDK docs for JSR-75 and this method says: "If the provided offset is larger than or equal to the current file size, the OutputStream is positioned at the current end of the file for appending."

Similar Threads

  1. Append String???
    By arun09 in forum Symbian
    Replies: 3
    Last Post: 2009-06-20, 05:42
  2. Replies: 8
    Last Post: 2008-03-05, 07:21
  3. Replies: 2
    Last Post: 2008-03-04, 19:24
  4. hot append the string using descriptor
    By ganngadhar in forum Symbian
    Replies: 14
    Last Post: 2007-04-10, 06:04
  5. Replies: 0
    Last Post: 2005-04-12, 07:25

Posting Permissions

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