• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

random access of file (r/w)

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
My pie came with a little toothpic holding up this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic