FileChannel没有写任何东西

时间:2014-06-23 14:00:02

标签: java endianness

我必须以小端顺序写一个整数。所以我用FileChannel属性和一些写方法创建了一个类(这个类没有扩展任何东西)。

但是有一个问题:只有一种方法有效,另一种方法没有!

这是工作方法(dis是FileChannel):

public void writeBuffer(ByteArrayOutputStream t) throws IOException
{
    ByteBuffer buffer=ByteBuffer.wrap(t.toByteArray());
    dis.write(buffer);
}

这是其中一种不起作用的写入方法:

public void writeInt(int t) throws IOException
{
    ByteBuffer buffer=ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN);
    buffer.putInt(t);
    dis.write(buffer);
}

我调试了程序,而dis.write(缓冲区)返回0,那有什么不对?

有没有人知道用little endian写4字节整数的替代方法?

0 个答案:

没有答案