Java-替代ByteArrayBuffer 解决missing in SDK23的问题

布满荆棘的人生 2022-07-17 01:30 10阅读 0赞

转载链接:http://blog.csdn.net/elonlink/article/details/52059064

问题:当SDK升级到23时候提示不存在**org.apache.http.util.ByteArrayBuffer**

1、使用ByteArraybuffer的代码

  1. BufferedInputStream bis = new BufferedInputStream(is);
  2. ByteArrayBuffer baf = new ByteArrayBuffer(50);
  3. while ((current = bis.read()) != -1) {
  4. baf.append((byte) current);
  5. }
  6. FileOutputStream fos = new FileOutputStream(file);
  7. fos.write(buffer.toByteArray());

2、使用ByteArrayOutputStream替代的代码

  1. BufferedInputStream bis = new BufferedInputStream(is);
  2. ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  3. //We create an array of bytes
  4. byte[] data = new byte[50];
  5. int current = 0;
  6. while((current = bis.read(data,0,data.length)) != -1){
  7. buffer.write(data,0,current);
  8. }
  9. FileOutputStream fos = new FileOutputStream(file);
  10. fos.write(buffer.toByteArray());
  11. fos.close();

发表评论

表情:
评论列表 (有 0 条评论,10人围观)

还没有评论,来说两句吧...

相关阅读

    相关 oracle 用EXISTS替代IN

    在许多基于基础表的查询中,为了满足一个条件,往往需要对另一个表进行联接.在这种情况下, 使用EXISTS(或NOT EXISTS)通常将提高查询的效率.  低效: SELE