<pre name="code" class="java">@Test
public void getFile(){
String fileUrl="http://static.zuchecdn.com/images/order/hg.jpg";
Integer fileId=1;
String path="d:/csms/"+fileId+".jpg";
System.out.print(path);
try{
URL url=new URL(fileUrl);
HttpURLConnection connection=(HttpURLConnection) url.openConnection();
connection.connect();
InputStream is=connection.getInputStream();
OutputStream os=new FileOutputStream(path);
BufferedOutputStream buffer=new BufferedOutputStream(os);
byte[] b=new byte[1024];
int len=0;
while((len=is.read(b))>0){
buffer.write(b,0,len);
}
buffer.flush();
os.close();
is.close();
}catch (Exception e) {
e.printStackTrace();
}
}
网络图片下载并保存本地
最新推荐文章于 2023-02-06 17:28:32 发布