• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileReader and FileWriter

 
divya madala
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • 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 ]
 
Joe Ess
Bartender
Pie
Posts: 9266
10
Linux Mac OS X Windows
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic