• 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

FileReader and FileWriter

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The below code doesn't work. Is there anyway how I can read only a particular line in a file and rewrite only that line?


[ May 03, 2004: Message edited by: divya madala ]
[ May 03, 2004: Message edited by: divya madala ]
[ May 03, 2004: Message edited by: divya madala ]
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.io.RandomAccessFile
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
RandomAcessFile will read or write content in the middle of a file, but it can only replace content of exactly the same length. If you try to replace "hello" with "goodbye" you'll clobber the next couple bytes of whatever followed. You cannot insert or delete content in the middle of a file ... it's just a limitation of the file system. (Some operating systems understand line-oriented files and support such actions.) You're pretty much stuck with reading the whole file, making changes and writing a new file. Such is life.
 
reply
    Bookmark Topic Watch Topic
  • New Topic