Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 28-07-2009
Member
 
Join Date: May 2008
Posts: 28
How to append an existing file in Java?

Hi,

As I said earlier I am new with JAVA. I want a code to add text to an existing file in java.
I mean I want to append to a file through java program.
How to append an existing file in Java?
Reply With Quote
  #2  
Old 28-07-2009
Member
 
Join Date: Apr 2008
Posts: 68
Re: How to append an existing file in Java?

It is actually very simple all you ne4ed to do is just add append option.

Code:
new FileOutputStream(f, true /* append */);
I hope you got this.
Reply With Quote
  #3  
Old 28-07-2009
Member
 
Join Date: Apr 2008
Posts: 44
Re: How to append an existing file in Java?

Append To File

You can use the class FileWriter and BufferedWriter to append the data to a file.

BufferedWriter

The BufferWriter class is used to write text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings.

Try This:

Code:
import java.io.*;
class FileWrite 
{
   public static void main(String args[])
  {
      try{
    // Create file 
    FileWriter fstream = new FileWriter("out.txt",true);
        BufferedWriter out = new BufferedWriter(fstream);
    out.write("Hello Java");
    //Close the output stream
    out.close();
    }catch (Exception e){//Catch exception if any
      System.err.println("Error: " + e.getMessage());
    }
  }
}
Reply With Quote
  #4  
Old 28-07-2009
Member
 
Join Date: Apr 2008
Posts: 51
Re: How to append an existing file in Java?

java append text to file

Code:
try {
BufferedWriter out = new BufferedWriter(new FileWriter("filename", true));
out.write("aString");
out.close();
} catch (IOException e) {}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to append an existing file in Java?"
Thread Thread Starter Forum Replies Last Post
How to append data to a text file in java? KALANI84 Software Development 4 05-02-2010 04:44 PM
Append text to end of file New ID Software Development 5 18-01-2010 09:35 AM
How can i make .cab file and would like to add file to an existing cab file Kamran Operating Systems 3 16-07-2009 01:29 PM
About keyword Append in SQL Ebenezer Software Development 2 11-04-2009 11:11 AM


All times are GMT +5.5. The time now is 04:22 AM.