Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Append Existing file in Java
04-19-2009, 12:15 AM
Post: #1
Append Existing file in Java
Hi,
Pls advise can i append an existing file in Java , If yes then How ?
Pls Explain.
Find all posts by this user
Quote this message in a reply
04-19-2009, 12:16 AM
Post: #2
RE: Append Existing file in Java
Appending data to a file is a fairly common task. You'll be surprised to know that there was no support for file appending in JDK1.02, and developers supporting that platform are forced to re-write the entire file to a temporary file, and then overwrite the original. As most users support either JDK1.1 or the Java 2 platform, you'll probably be able to use the following FileOutputStream constructor to append data:

public FileOutputStream(String name,
boolean append)
throws FileNotFoundException

Parameters:
name - the system-dependent file name
append - if true, then bytes will be written to the end of the file rather than the beginning

For example, to append the file 'autoexec.bat' to add a new path statement on a Wintel machine, you could do the following:

FileOutputStream appendedFile = new FileOutputStream
("c:\\autoexec.bat", true);
Find all posts by this user
Quote this message in a reply
01-30-2010, 03:24 PM
Post: #3
RE: Append Existing file in Java
Appending data to a file is a fairly common task. You'll be surprised to know that there was no support for file appending in JDK1.02, and developers supporting that platform are forced to re-write the entire file to a temporary file, and then overwrite the original. As most users support either JDK1.1 or the Java 2 platform.

Learn dancing
Find all posts by this user
Quote this message in a reply
02-03-2010, 12:28 AM
Post: #4
RE: Append Existing file in Java
You can easily append data to the end of the text file by using the Java FileWriter and BufferedWriter classes. In particular, the most important part of the solution is to invoke the FileWriter constructor in the proper manner.

Black leather bags
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: