Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

random access of file (r/w)  RSS feed

 
Amit Lal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Need to random access a record and update it with new string without affecting rest of the file.
num = randTest.getFilePointer();
temp = randTest.readLine();
while(temp != null){
if (temp.startsWith("222")){
randTest.seek(num);
randTest.writeChars("222 ffff\n");
}
num = randTest.getFilePointer();
temp = randTest.readLine();
}
file is:
111 aaaa
222 bbbb
333 cccc
messes up the last line!!
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"alal"
Welcome to the JavaRanch! Please adjust your displayed named to match the JavaRanch Naming Policy.
You can adjust it here.
Thanks! and welcome to the JavaRanch!
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In what way does it "mess up the last line"? What does the final line look like?
 
Amit Lal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this code it deletes the last line. Output is,
111 aaaa
222 ffff

In a few cases that I have tried, it gives an output like
111 aaaa
222 ffff
33 cccc
[ May 15, 2002: Message edited by: Amit Lal ]
[ May 15, 2002: Message edited by: Amit Lal ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!