您的位置:首页 > 其它

远程url文件地址转成byte

2016-03-16 13:42 495 查看
public static byte[] urlTobyte(String url) throws MalformedURLException {
URL ur = new URL(url);
BufferedInputStream in = null;
ByteArrayOutputStream out = null;
try {
in = new BufferedInputStream(ur.openStream());
out = new ByteArrayOutputStream(1024);
byte[] temp = new byte[1024];
int size = 0;
while ((size = in.read(temp)) != -1) {
out.write(temp, 0, size);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
byte[] content = out.toByteArray();
return content;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: