Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing Javolution Struct to RandomAccessFile

Status
Not open for further replies.
Jun 22, 2000
6,317
AU
Please excuse the basic nature of this question, I'm not a fluent Java
programmer.

I'm trying to write a simple Javolution Struct to a RandomAccessFile but
keep on getting unusual exceptions or short writes (only 46 bytes being
written instead of the 212 bytes in the Struct, for example).

selectedSetup is of class Setup, which is an extension of the Struct class.

Code:
     RandomAccessFile f = new RandomAccessFile(selectedTrack.csuFile,"rw");
     selectedSetup.getByteBuffer().position(0);
     // this results in a partial write
     int written=f.getChannel().write(selectedSetup.getByteBuffer());
     // this results in a java.lang.UnsupportedOperationException
     f.write(selectedSetup.getByteBuffer().array(),212,0);
     f.close();

Previously I was reading these structures using stream I/O which worked
perfectly, but realised I needed switch to java.nio.channels to modify
RandomAccessFiles. I must be missing something obvious here?

Annihilannic.
 
This was solved, apparently f.getChannel().write(selectedSetup.getByteBuffer()) was the correct method; I think I forgot to set the position() before using that method, and only added that after trying the second way.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top