使用NIO怎样将内存中的非Byte类型数据写到硬盘上?
比如说我现在有一个int[],怎么把它写在硬盘上?File file = new File("data.tmp");
FileOutputStream fileOutputStream = new FileOutputStream(file
FileChannel fileChannel = fileOutputStream.getChannel();int[] data = ((DataBufferInt) dataBuffer).getData();
IntBuffer intBuffer = IntBuffer.wrap(data);fileChannel.write();
====================
这个方法只能写ByteBuffer类型。我对NIO一知半解,希望能得到大家的帮助。
比如说我现在有一个int[],怎么把它写在硬盘上?File file = new File("data.tmp");
FileOutputStream fileOutputStream = new FileOutputStream(file
FileChannel fileChannel = fileOutputStream.getChannel();int[] data = ((DataBufferInt) dataBuffer).getData();
IntBuffer intBuffer = IntBuffer.wrap(data);fileChannel.write();
====================
这个方法只能写ByteBuffer类型。我对NIO一知半解,希望能得到大家的帮助。
所以可以把你要写入的转化成byte数组就可以了,然后用此byte数据构造一个ByteBuffer
这样不就可以写了吗