How to output values to a file for different runs

R

ram

Hi,

I'm getting output values for every time i run my program. But every
time that output file doesn't append the output the values. It simply
overwrites the previous contents. What should be done in order to
write the next output in a line next to the previous output.
 
M

Mark Space

ram said:
Hi,

I'm getting output values for every time i run my program. But every
time that output file doesn't append the output the values. It simply
overwrites the previous contents. What should be done in order to
write the next output in a line next to the previous output.

I think you probably have to use RandomAccessFile. Call seek() to skip
to the end.
 
M

Manish Pandit

Hi,

I'm getting output values for every time i run my program. But every
time that output file doesn't append the output the values. It simply
overwrites the previous contents. What should be done in order to
write the next output in a line next to the previous output.

Are you running the code command line and redirecting the output to a
file? If yes, then instead of:

java MyCode > output.txt use java MyCode >> output.txt

If you are opening up the file to write from within your code, then
follow Mark's suggestion to open the file, seek to the end and then
write.

-cheers,
Manish
 
D

Daniel Pitts

ram said:
Hi,

I'm getting output values for every time i run my program. But every
time that output file doesn't append the output the values. It simply
overwrites the previous contents. What should be done in order to
write the next output in a line next to the previous output.
Please post your question only once, it might take some time for it to
propagate through usenet. Generally, you should wait at least 72 hours
before following up.

Also, the best way to follow up is to reply to your existing post,
preferebly with more information (such as what you've tried on your own
since your last post, and why it didn't seem to work).
 
R

Roger Lindsjö

Mark said:
I think you probably have to use RandomAccessFile. Call seek() to skip
to the end.

Or just open the file for appending, such as:

OutputStream out = new FileOutputStream("thefile", true);

//Roger Lindsjö
 
L

Lew

Roger said:
Or just open the file for appending, such as:

OutputStream out = new FileOutputStream("thefile", true);

This matches the answer given the OP on the other thread on this question.
 
R

Roger Lindsjö

Lew said:
This matches the answer given the OP on the other thread on this question.

Do you mean the answer by Daniel Pitts on the thread "To output values
to the same file for different outputs"? If so, yeah, I saw that as I
continued processing the group.

Or did you mean some other post? I can't help but reading your comment
as if I had plagiarized someone else, did you?

//Roger Lindsjö
 
L

Lew

Roger said:
Do you mean the answer by Daniel Pitts on the thread "To output values
to the same file for different outputs"? If so, yeah, I saw that as I
continued processing the group.

Or did you mean some other post? I can't help but reading your comment
as if I had plagiarized someone else, did you?

What? No! I'm not accusing anyone of plagiarizing - Gods forfend. I just
wanted to let people know that there were two threads on this same question so
we could unify the conversation.

I deeply apologize for leaving the kitty door open a crack on the
interpretation of plagiarism, but let me assure you that were I to smell
plagiarism I would explicitly use the term; you would not need to stretch any
of your imagination to infer it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,797
Messages
2,569,647
Members
45,377
Latest member
Zebacus

Latest Threads

Top