private void downloadServerPic(final String url1) {
new Thread() {
@Override
public void run() {
// 定义一个URL对象
URL url;
try {
url = new URL(url1);
// 打开该URL的资源输入流
InputStream is = url.openStream();
is.close();
// 再次打开RL对应的资源输入流
is = url.openStream();
//创建输出流
FileOutputStream outStream = null;
try {
byte[] bary = readInputStream(is);
File imageFile = new File( Environment.getExternalStorageDirectory() + "/DCIM/UxinUsedCar/"+"share.jpg");
outStream = new FileOutputStream(imageFile);
//写入数据
outStream.write(bary);
//getimage 方法见 http://www.cnblogs.com/wangzehuaw/p/4447120.html
bitMap = getimage( Environment.getExternalStorageDirectory() + "/DCIM/UxinUsedCar/"+"share.jpg");
//关闭输出流
} catch (Exception e) {
e.printStackTrace();
} finally {
if(outStream != null)
outStream.close();
is.close();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}