473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Append to exsisting text file

Hi,

I'm hoping for some guideance. I'm trying append to the bottom of a text
file using Java.

Any advice, further reading would be greatly appreciated!

Cheers,
Dave
Jul 17 '05 #1
5 86999
See

public PrintWriter(Writer out,
boolean autoFlush)

--
Luca Paganelli
ICQ# 52629494
Jul 17 '05 #2
See

FileWriter
public FileWriter(String fileName,
boolean append)
throws IOException

Constructs a FileWriter object given a file name with a boolean
indicating whether or not to append the data written.

Sample code:

BufferedWriter writer = new BufferedWriter(
new FileWriter("myfile.txt",true)) ;
writer.write("HELLO") ;
writer.close() ;

Fahd Shariff
http://www.fahdshariff.cjb.net
"Let the code do the talking..."
Jul 17 '05 #3
Thanks for that, but i'm hoping you can help me with my syntax. It
currently makes a new text file/replaces but i'm unsure how to append an
already exsisting one.

This is what i have:

try
{
String outName = "out.txt";
FileWriter out = new FileWriter(outName);
writer.write(total);
writer.newLine();
writer.close();
}

Thanks,
Dave

"Fahd Shariff" <fa*********@yahoo.com> wrote in message
news:9b**************************@posting.google.c om...
See

FileWriter
public FileWriter(String fileName,
boolean append)
throws IOException

Constructs a FileWriter object given a file name with a boolean
indicating whether or not to append the data written.

Sample code:

BufferedWriter writer = new BufferedWriter(
new FileWriter("myfile.txt",true)) ;
writer.write("HELLO") ;
writer.close() ;

Fahd Shariff
http://www.fahdshariff.cjb.net
"Let the code do the talking..."

Jul 17 '05 #4
Sorry, let me correct that:

try
{
//ask user for file name to write to

FileWriter out = new FileWriter("out.txt");
BufferedWriter writer = new BufferedWriter(out);
writer.write(total);
writer.close();
}
Jul 17 '05 #5
Change to :
FileWriter out = new FileWriter("out.txt", true);

If the file does not exist it is created and if it does, text is appended to it.

Fahd Shariff
http://www.fahdfshariff.cjb.net
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Amjad | last post by:
How can I append a text file to another? Amajd
2
by: Roy Gourgi | last post by:
Hi, How could I append a text file to another text file. Let's say that I have a File1 and I want to append File2 at the end of File1, how would I do that? TIA Roy
3
by: Macca | last post by:
Hi, I am writing some information to a text file using the TextWriter Class. However I am having problems appending data to a file that already exists and already has text in it. I just seem...
3
by: Luke | last post by:
I'm pretty stuck at the moment and wondering if anyone can spot the problem. Trying to create a function that will read a text file into a list and return that list. I wrote the following...
9
by: andy.z | last post by:
If 2 people try to access the same text file at the same time to write to it - what happens in PHP ? What I mean is - presumably the first will be ok - But what will the second person actually...
2
by: hash4sp | last post by:
I have just started my career in programming. My Problem is reading a text file using VB.NET. The text contains the state names followed by respective city names. My task is to read the file and...
2
by: sajidali | last post by:
i am trying to append a text file using c#. when i executes my application i writes to the text file using more then one functions. i want to append file only during execution of programe. next time...
1
by: wish | last post by:
Hello, I have problem is when i append new data in text file always append at the last of the text file. Am i can append the new data in beginning of the text file? Mean when i have update data...
2
by: Andez | last post by:
I've wrote a windows service that performs simple functions within our application. To ensure safe running of the service - if it errors we want to know where when how - it logs to a text file - in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.