943,719 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 10777
  • Java RSS
Jun 9th, 2004
0

10 line text file

Expand Post »
Hi all,

I need to maintain a text file which contains only 10 lines.

As a new line is added to the top - a line is removed from the bottom.

So although the file is automatically updated regularly it will always contain only 10 lines.

I know how to create a new text file but not how to add a line of text to the top or remove a line from the bottom.

Any assistance would be great,

Cheers


Jeff
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JeffSyd is offline Offline
1 posts
since Jun 2004
Jun 21st, 2004
0

Re: 10 line text file

Parse the file as a string, then find char position of the second to last line return, substring from 0th char to 2nd last CR/LR (removing bottom line), and append this substring to the line you want at the top...?
oldFile >> originalString;
substring = originalString - last line;
newString = newText + substring;
newString >> newFile;
I think this will work, it's been over half a year since I last used java so I may be a bit rusty. (There are probably better ways of doing this also.. )
Reputation Points: 21
Solved Threads: 1
Posting Whiz in Training
szukalski is offline Offline
295 posts
since Jun 2004
Jun 21st, 2004
0

Re: 10 line text file

Greetings.
Cool, I should say.
Sorry to interrupt on the thread.
How about this:-
Quote ...
I have a text file which is a file for "Hall Of Fame" in a small game program. It's a 10 lines file too - top tens will enter only. So, my question here is, how can I delete the last line (to eliminate the last one standing due to an occurence of a new record breaker.) from the file and add a line wherever it may apply?
Thanks.
Reputation Points: 53
Solved Threads: 1
Posting Whiz
red_evolve is offline Offline
313 posts
since Jun 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Key Press event Restriction
Next Thread in Java Forum Timeline: Automating survey results to email on submit.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC