我必须写一个文件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)