Sunday, 15 August 2010

java - FileChannel doesn't write anything -



java - FileChannel doesn't write anything -

i have write integer in little endian order. i've created class (this class not extend anything) filechannel attribute , write methods.

but there's problem: 1 method works, other not!

here working method (dis filechannel):

public void writebuffer(bytearrayoutputstream t) throws ioexception { bytebuffer buffer=bytebuffer.wrap(t.tobytearray()); dis.write(buffer); }

and 1 of write methods doesn't work:

public void writeint(int t) throws ioexception { bytebuffer buffer=bytebuffer.allocate(4).order(byteorder.little_endian); buffer.putint(t); dis.write(buffer); }

i debugged programme , dis.write(buffer) returns 0, what's wrong?

does know alternative method writing 4 byte integers in little endian?

when create bytebuffer (such bytebuffer.wrap or bytebuffer.allocate), created position @ zero. in sec method, phone call putint, advances bytebuffer's position 4 (the end of buffer), bytebuffer reports there no more bytes read.

there number of methods reset buffer's position. comments have stated, flip best choice, since intended called when have placed info in buffer , want other code start reading data.

java little-endian

No comments:

Post a Comment