General [M]ayhem

Go Back   General [M]ayhem > Real Time Sub-Forums > CompuGlobalHyperMegaNet
Register Members List Mark Forums Read [M]erchandise Calendar

Reply
 
Thread Tools
jkoebel
 
Quick java file IO question.

I need some psuedocode as to how to swap a line of a file, with the last line of the file.

That'd be very helpful.

No, I'm not doing this for a class. I'm trying to patch an app I'm working with to behave differently, and I don't know Java well enough to do so.

Last edited by jkoebel; 03-29-2005 at 08:06 AM..
Old 03-29-2005, 07:58 AM jkoebel is offline  
Reply With Quote
#1  

Advertisement [Remove Advertisement]

dolmant
 
Use a FileReader to open the thing, and then use a StringTokenizer to get each line. Do the swap then write it back out with a FileWriter.
Old 03-29-2005, 11:38 AM dolmant is offline  
Reply With Quote
#2  

jkoebel
 
Thanks dolmant.

A requirement of this project (due to memory) was that the file must be manipulated on-disk as much as possible, and not read into memory.

What I ended up doing wasn't quite what I was looking for, but is functionally identical: flag items that are "deleted" as being so, and then when something comes along looking to add to the file, it first looks at the "deleted" ones and will overwrite those preferentially to appending to the end of the file.

So, it works, and I didn't need to do quite as much work on it.
Old 03-29-2005, 12:27 PM jkoebel is offline  
Reply With Quote
#3  

Psyduck
 
Psyduck's Avatar
 
So were lines in the file fixed width?
__________________
and maybe somebody's daughter
Old 03-29-2005, 12:43 PM Psyduck is offline  
Reply With Quote
#4  

Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -7. The time now is 11:40 AM.



Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.