替代ByteArrayBuffer 解决missing in SDK23的问题

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

1、使用ByteArraybuffer的代码

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


2、使用ByteArrayOutputStream替代的代码

    BufferedInputStream bis = new BufferedInputStream(is);
     ByteArrayOutputStream buffer = new ByteArrayOutputStream();
     //We create an array of bytes
     byte[] data = new byte[50];
     int current = 0;

     while((current = bis.read(data,0,data.length)) != -1){
           buffer.write(data,0,current);
     }

     FileOutputStream fos = new FileOutputStream(file);
     fos.write(buffer.toByteArray());
     fos.close();

原文链接

你可能感兴趣的:(Android,Java)