InputStream io = null;
ByteArrayOutputStream out = null;
byte[] buff = null;
try{
URL url = new URL(uri);
URLConnection conn = url.openConnection();
io = conn.getInputStream();
out = new ByteArrayOutputStream();
int byteWritten = 0;
int byteCount = 0;
buff = new byte[size];
while((byteCount = io.read(buff)) != -1){
out.write(buff,byteWritten,byteCount);
}
} catch(Exception e){
e.printStackTrace();
}
其中:uri为统一资源定位符,类型为字符串;
size为字节数组的大小,根据写入的uri内容大小来规定