java endian_java – 将小Endian文件转换成大Endian
发布日期:2021-08-19 22:48:24 浏览次数:18 分类:技术文章

本文共 563 字,大约阅读时间需要 1 分钟。

打开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();

要正确处理输入的字节顺序,您需要准确地知道文件中存储的内容以及以什么顺序(所谓的协议或格式).

转载地址:https://blog.csdn.net/weixin_30962449/article/details/115020760 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:java使用joblib模型_python打包exe 之打包sklearn模型中的各种坑及其解决方法。
下一篇:python 测试端口连通_python探测服务器端口连通性

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年12月28日 20时17分35秒