[color=red]思路: 要有一个读取的来源。。。。不是reader 就是 inputStream[/color]
[color=blue]要有一个读取的目的地: 不是 StringBuffer 就是 OutputStream(要么写入内存中的字符串中,要么写入硬盘中)[/color]
[color=red]因为不是一下读完 所以要临时存储器 不是 String 就是 byte[] [/color]
[color=blue]inpuStream哪里多了个记录长度的 int len 而已,是为了配合byte[/color]
BufferedReader rd =
new BufferedReader(new InputStreamReader(
conn.getInputStream()));//[color=red]得到读取流[/color]
StringBuffer sb = new StringBuffer();//[color=red]接受者[/color]
String line; //[color=blue]临时存储器[/color]
while ((line = rd.readLine()) != null) {//读取
sb.append(line); //写入
}
rd.close();
//========================inputStream==========================
URL url = new URL(imgurl);
BufferedInputStream bis = new BufferedInputStream(url.openStream());//[color=red]得到读取流[/color]
//实例化存储字节数组
byte[] bytes = new byte[100];//[color=blue]临时存储器[/color]
//设置写入路径以及图片名称
OutputStream bos = new FileOutputStream(new File( "C:\\thetempimg.gif"));//[color=red]接收者[/color]
int len;
while ((len = bis.read(bytes)) > 0) {//读取
bos.write(bytes, 0, len); //写入
}
[color=blue]要有一个读取的目的地: 不是 StringBuffer 就是 OutputStream(要么写入内存中的字符串中,要么写入硬盘中)[/color]
[color=red]因为不是一下读完 所以要临时存储器 不是 String 就是 byte[] [/color]
[color=blue]inpuStream哪里多了个记录长度的 int len 而已,是为了配合byte[/color]
BufferedReader rd =
new BufferedReader(new InputStreamReader(
conn.getInputStream()));//[color=red]得到读取流[/color]
StringBuffer sb = new StringBuffer();//[color=red]接受者[/color]
String line; //[color=blue]临时存储器[/color]
while ((line = rd.readLine()) != null) {//读取
sb.append(line); //写入
}
rd.close();
//========================inputStream==========================
URL url = new URL(imgurl);
BufferedInputStream bis = new BufferedInputStream(url.openStream());//[color=red]得到读取流[/color]
//实例化存储字节数组
byte[] bytes = new byte[100];//[color=blue]临时存储器[/color]
//设置写入路径以及图片名称
OutputStream bos = new FileOutputStream(new File( "C:\\thetempimg.gif"));//[color=red]接收者[/color]
int len;
while ((len = bis.read(bytes)) > 0) {//读取
bos.write(bytes, 0, len); //写入
}