62,623
社区成员
发帖
与我相关
我的任务
分享
FileOutputStream fout = null;
try {
fout = new FileOutputStream("d://temp//1.html");
URL conn= new URL("http://www.sina.com/");
InputStream in=conn.openStream();
int n=in.available();
byte[] buf=new byte[1024];
while((n=in.read(buf)) >=0){
System.out.write(buf,0,n);
fout.write(buf);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if(fout != null) {
try {
fout.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
try {
fout = new FileOutputStream("d://temp//1.html");
URL conn= new URL("http://www.sina.com/");
InputStream in=conn.openStream();
int n=in.available();
byte[] buf=new byte[1024];
while((n=in.read(buf)) >=0){
System.out.write(buf,0,n);
fout.write(buf);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if(fout != null) {
try {
fout.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}