aspose file tools*
The moose likes I/O and Streams and the fly likes ObjectInputStream 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 "ObjectInputStream" Watch "ObjectInputStream" New topic
Author

ObjectInputStream

sreek, Thiru
Greenhorn

Joined: Feb 21, 2001
Posts: 10
I am trying to read a file and skip some bytes ... using "skipBytes" method, but it always skips zero bytes irrespective of what the argument is....
here is the code.
long fp...(from some other method)
fos = new FileInputStream("emp.ser");
bos = new BufferedInputStream(fos);
oos = new ObjectInputStream(fos);
try{
int avail = oos.available();
System.out.println("avail = " + avail);
int b = oos.skipBytes( (int)fp);
if(b != (int)fp )
System.out.println("b =" + b + " & fp = " + fp);
}
catch( Exception e) { e.printStackTrace(); }

output is :
avail = 0
b=0 & fp = given val
I am striving with this from past 10 to 12 hrs ... someone please help me.
Jim Baiter
Ranch Hand

Joined: Jan 05, 2001
Posts: 532
This is from the API doc for skipBytes() in the DataInputStream class which the ObjectInputStream is using.
"Makes an attempt to skip over n bytes of data from the input stream, discarding the skipped bytes. However, it may skip over some smaller number of bytes, possibly zero. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. This method never throws an EOFException. The actual number of bytes skipped is returned."
What you should probably do is just loop calling readByte() in each iteration for the number of bytes you want to skip or you could create a byte[] of that length and call readFully().
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ObjectInputStream