ByteArrayInputStream无法读取ByteArrayOutputStream在Java中写入的long类型数据。
创始人
2025-01-12 20:30:42
0
  1. 使用DataInputStream和DataOutputStream将数据以二进制格式进行读写。

示例代码:

ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); dos.writeLong(number);

byte[] bytes = bos.toByteArray(); ByteArrayInputStream bis = new ByteArrayInputStream(bytes); DataInputStream dis = new DataInputStream(bis); long readLong = dis.readLong();

  1. 将long类型数据转换为字节数组,然后再读取字节数组。

示例代码:

ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); buffer.putLong(number); bos.write(buffer.array());

byte[] bytes = bos.toByteArray(); ByteArrayInputStream bis = new ByteArrayInputStream(bytes);

byte[] longBytes = new byte[Long.BYTES]; bis.read(longBytes, 0, Long.BYTES); long readLong = BitConverter.toInt64(longBytes, 0);

注意:使用第二种方法需要在代码中添加BitConverter类的实现,或使用Java的BigInteger类进行转换。

相关内容

热门资讯

玩家必备攻略!wepoker破... 玩家必备攻略!wepoker破解器有用吗(辅助挂)都是有挂(有挂解密辅助器)1、上手简单,内置详细流...
分享认知!hhpoker真的有... 分享认知!hhpoker真的有透视吗(辅助挂)其实有挂(新版有挂辅助工具)1、每一步都需要思考,不同...
揭秘攻略!智星德州插件最新版本... 揭秘攻略!智星德州插件最新版本更新内容详解(辅助挂)都是是有挂(详细教程辅助技巧)能透视中分为三种模...
实操分享!约局吧德州有挂吗(辅... 实操分享!约局吧德州有挂吗(辅助挂)本来真的有挂(有挂秘籍辅助攻略)1、玩家可以在线上大神俱乐部对游...
玩家攻略!hhpoker作弊码... 玩家攻略!hhpoker作弊码(辅助挂)其实真的有挂(有挂神器辅助技巧)1、点击下载安装,脚本分类一...
查到实测辅助!hhpoker到... 查到实测辅助!hhpoker到底可以作弊吗(辅助挂)切实有挂(竟然有挂辅助软件)1、破解器简单,机器...
推荐十款!wepoker游戏的... 推荐十款!wepoker游戏的安装教程(辅助挂)切实是真的有挂(竟然有挂辅助脚本)1、上手简单,内置...
必备攻略!hhpkoer辅助器... 必备攻略!hhpkoer辅助器(辅助挂)都是真的有挂(揭秘有挂辅助技巧)辅助器是一种具有地方特色的麻...
总算了解!wepoker有辅助... 总算了解!wepoker有辅助器吗(辅助挂)切实存在有挂(有挂方法辅助软件)1、金币登录送、破产送、...
记者爆料!wepoker开辅助... 记者爆料!wepoker开辅助能查到吗(辅助挂)切实是有挂(有挂解密辅助方法)1、游戏颠覆性的策略玩...