User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 427,668 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,283 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 6778 | Replies: 2
Reply
Join Date: Jun 2004
Posts: 1
Reputation: JeffSyd is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
JeffSyd JeffSyd is offline Offline
Newbie Poster

10 line text file

  #1  
Jun 8th, 2004
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2004
Location: Aotearoa
Posts: 295
Reputation: szukalski is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 1
szukalski szukalski is offline Offline
Posting Whiz in Training

Re: 10 line text file

  #2  
Jun 20th, 2004
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.. )
Overclocking is for geeks. I'm such a geek.
Reply With Quote  
Join Date: Jun 2003
Location: Malaysia
Posts: 313
Reputation: red_evolve is on a distinguished road 
Rep Power: 6
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Re: 10 line text file

  #3  
Jun 21st, 2004
Greetings.
Cool, I should say.
Sorry to interrupt on the thread.
How about this:-
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 11:06 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC