aspose file tools*
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
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: 8900
    
    8

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FileReader and FileWriter