小编abo*_*ill的帖子

用小端写一个整数

我必须写一个文件4bytes表示一个小端的整数(java使用大端),因为外部c ++应用程序必须读取此文件.我的代码不在te文件中写任何东西,但de buffer里面有数据.为什么?我的功能:

public static void copy(String fileOutName, boolean append){
    File fileOut = new File (fileOutName);

    try {
         FileChannel wChannel = new FileOutputStream(fileOut, append).getChannel();

         int i = 5;
         ByteBuffer bb = ByteBuffer.allocate(4);
         bb.order(ByteOrder.LITTLE_ENDIAN);
         bb.putInt(i);

         bb.flip();

         int written = wChannel.write(bb);
         System.out.println(written);    

         wChannel.close();
     } catch (IOException e) {
     }
}
Run Code Online (Sandbox Code Playgroud)

我的电话:

copy("prueba.bin", false);
Run Code Online (Sandbox Code Playgroud)

java io nio bytebuffer endianness

4
推荐指数
1
解决办法
4764
查看次数

标签 统计

bytebuffer ×1

endianness ×1

io ×1

java ×1

nio ×1