- import java.io.DataOutputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.nio.ByteBuffer;
- import java.nio.ByteOrder;
- public class ghgfh
- {
- public static void main(String[] args) throws IOException
- {
- int i = 12345678;
-
- FileOutputStream fou = new FileOutputStream("test_dout.data");
- DataOutputStream dou = new DataOutputStream(fou);
- dou.writeInt(i);
- dou.close();
-
-
- ByteBuffer Buffer = ByteBuffer.allocate(4);
- Buffer.order(ByteOrder.nativeOrder()); //将新建的ByteBuffer设置为本机的字节顺
- Buffer.putInt(i);
- Buffer.flip();
- FileOutputStream nfou = new FileOutputStream("test_nbuf.data");
- nfou.write(Buffer.array());
- nfou.close();
- System.out.println(ByteOrder.nativeOrder());
- }
- }
复制代码 |