noor 最近的时间轴更新
noor

noor

V2EX 第 444451 号会员,加入于 2019-10-02 23:42:06 +08:00
noor 最近回复了
过了几个月了突然想起这个问题已经解决了。
问题代码:chipToolResource.getInputStream().available()获取的的字节大小并不一定准确
每个平台实现的实现不一样,windows 上是正确的,linux 上不一定正确。
文档中也有说:
* <p> Note that while some implementations of {@code InputStream} will return
* the total number of bytes in the stream, many will not. It is
* never correct to use the return value of this method to allocate
* a buffer intended to hold all data in this stream.

byte[] chipToolBytes = new byte[chipToolResource.getInputStream().available()];
换了种方式就可以了
File outputFile = new File(tmp+"/chip-cert");
OutputStream outputStream = new FileOutputStream(outputFile);
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
@wowo243 不行,比较发现文件里面的内容错乱了。考虑换种写文件方式尝试下。
@momocraft 文件内容不对
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1008 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 12ms · UTC 18:58 · PVG 02:58 · LAX 11:58 · JFK 14:58
Developed with CodeLauncher
♥ Do have faith in what you're doing.