您的位置:首页 > 编程语言 > Java开发

java中二进制和流的相互转换

2016-01-05 10:04 405 查看
流转二进制

public static byte[] toByteArray(InputStream in) throws IOException {
ByteArrayOutputStream out=new ByteArrayOutputStream();
byte[] buffer=new byte[1024*4];
int n=0;
while ( (n=in.read(buffer)) !=-1) {
out.write(buffer,0,n);
}
return out.toByteArray();
}


二进制转流

public static byte[] toInputStream(byte[] b) throws IOException {
returnInputStream inputStream = new ByteArrayInputStream(b);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: