| | |
10 line text file
![]() |
•
•
Join Date: Jun 2004
Posts: 1
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Jun 2004
Posts: 295
Reputation:
Solved Threads: 1
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.. )
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.
Greetings.
Cool, I should say.
Sorry to interrupt on the thread.
How about this:-
Thanks.
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?
![]() |
Similar Threads
- Help-Read line from the text file (Java)
- read line of text from file into array (C++)
- how to delete the last line of the text file using c# (ASP.NET)
- reading more then 1 line of text in file (C++)
- Read a particular line from a text file (C)
- Read a specific line from a text file - how to ? (Java)
- how do i read the last line of a text file? (Python)
Other Threads in the Java Forum
- Previous Thread: Key Press event Restriction
- Next Thread: Automating survey results to email on submit.
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp functiontesting game gameprogramming givemetehcodez graphics gui health html ide idea image int j2me j2seprojects java javac javaee javame javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux mac main map method mobile myregfun netbeans nonstatic notdisplaying number online printf problem program project qt researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor





