Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

How to output values to a file for different runs

Thread view: 
ram - 28 Nov 2007 16:10 GMT
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.
Mark Space - 28 Nov 2007 18:02 GMT
> 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.
Roger Lindsjö - 29 Nov 2007 07:52 GMT
>> Hi,
>>
[quoted text clipped - 5 lines]
> 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ö
Lew - 29 Nov 2007 14:26 GMT
> 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.

Signature

Lew

Roger Lindsjö - 29 Nov 2007 14:40 GMT
>> 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.

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ö
Lew - 29 Nov 2007 14:48 GMT
>>> Or just open the file for appending, such as:
>>>
[quoted text clipped - 9 lines]
> 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.

Signature

Lew

Manish Pandit - 28 Nov 2007 18:17 GMT
> 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
Daniel Pitts - 28 Nov 2007 18:45 GMT
> 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).

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Roedy Green - 29 Nov 2007 01:33 GMT
>What should be done in order to
>write the next output in a line next to the previous output.

If you mean tack it on the end, see
http://mindprod.com/applet/fileio.html

there is a parameter you can specify at file open.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.