java endian_java – 将小Endian文件转换成大Endian
生活随笔
收集整理的這篇文章主要介紹了
java endian_java – 将小Endian文件转换成大Endian
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
打開NIO FileChannel:
FileInputStream fs = new FileInputStream("myfile.bin");
FileChannel fc = fs.getChannel();
設置ByteBuffer endianness(由[get | put]使用)Int(),[get | put] Long(),[get | put] Short(),[get | put] Double()
ByteBuffer buf = ByteBuffer.allocate(0x10000);
buf.order(ByteOrder.LITTLE_ENDIAN); // or ByteOrder.BIG_ENDIAN
從FileChannel讀取到ByteBuffer
fc.read(buf);
buf.flip();
// here you take data from the buffer by either of getShort(), getInt(), getLong(), getDouble(), or get(byte[], offset, len)
buf.compact();
要正確處理輸入的字節(jié)順序,您需要準確地知道文件中存儲的內容以及以什么順序(所謂的協(xié)議或格式).
總結
以上是生活随笔為你收集整理的java endian_java – 将小Endian文件转换成大Endian的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html5页面文件打包,Webpack入
- 下一篇: left join on和 join o