public static void binWriteTest() { int _int = 12345678; ByteBuffer _nbuffer = ByteBuffer.allocate(4); _nbuffer.order(ByteOrder.nativeOrder()); // 将新建的ByteBuffer设置为本机的字节顺 _nbuffer.putInt(_int); _nbuffer.flip(); try { FileOutputStream _fou = new FileOutputStream("test_dout.data"); FileOutputStream _nfou = new FileOutputStream("test_nbuf.data"); DataOutputStream _dou = new DataOutputStream(_fou); _dou.writeInt(_int); _dou.close(); _nfou.write(_nbuffer.array()); _nfou.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(ByteOrder.nativeOrder()); _int = 789; String strteString = "abcdefghi>-1245:"; float fval = 1234567.11f; try { FileOutputStream _nfou = new FileOutputStream( Constant.DATADIR_STRING + "test_nbuf.data"); DataOutputStream _dou = new DataOutputStream(_nfou); _dou.writeInt(_int); _dou.writeFloat(fval); _dou.writeUTF(strteString); ; _dou.close(); FileInputStream _nfin = new FileInputStream(Constant.DATADIR_STRING + "test_nbuf.data"); DataInputStream _din = new DataInputStream(_nfin); _int = _din.readInt(); fval = _din.readFloat(); strteString = _din.readUTF(); _din.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }