*
The moose likes I/O and Streams and the fly likes FileReader and FileWriter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "FileReader and FileWriter" Watch "FileReader and FileWriter" New topic
Author

FileReader and FileWriter

divya madala
Ranch Hand

Joined: Jan 10, 2001
Posts: 61
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

Joined: Oct 29, 2001
Posts: 8834
    
    7

java.io.RandomAccessFile


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
jQuery in Action, 2nd edition
 
subject: FileReader and FileWriter
 
Similar Threads
reading a file by lines
reading a file by lines
How to load a dictionary file into a de la briandais tree?
retrieving data from a text file
comparing two files