• 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

using the reset() method in InputStream Class

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Following is the code that i wrote to practice I/O. i waned to write the array b in the file, then reset the pointer to the beginning of the output file so that i cd overwrite stuff from the input file (test.txt)

a. i get a compile time error saying that the reset method not found in FileOutputStream class.
b. when i extend the OutputStream class to use the reset()method, it says in have to provide an implementation for the read() method.
question: all i want to do is to reset the pointer in my output file after writing the araay b. how can i do it??

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using the RandomAccesFile class.
Stream classes are like a data(water) flowing
down a stream. It doesn't flow back upstream.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reset method is provided in certain InputStream methods that have a buffer of characters or bytes. The method is there so that you can mark a point in the input stream, read some data, and then reset the stream to the marked point.
Naturally the amount of data you can read is restricted by the buffer size.
 
mansoor iqbal
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Robert: if it is like water, then why provide the reset() method?
Bill: there has to be more than that...the API documentation mentions mark but also says beginning of file in case there is no last mark found.....
am still in the air
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic