日期:2014-05-20 浏览次数:20781 次
public String saveToFile(String destUrl, String pathName) { FileOutputStream fos = null; BufferedInputStream bis = null; HttpURLConnection httpUrl = null; URL url = null; String fullPath = null; byte[] buf = new byte[BUFFER_SIZE]; int size = 0; try { url = new URL(destUrl); httpUrl = (HttpURLConnection) url.openConnection(); httpUrl.connect(); bis = new BufferedInputStream(httpUrl.getInputStream()); fullPath = getFullPath(pathName,this.fileFormat); fos = new FileOutputStream(fullPath); while ( (size = bis.read(buf)) != -1) { fos.write(buf, 0, size); } fos.flush(); } catch(IOException e) { } catch(ClassCastException e) { } finally { try { fos.close(); bis.close(); httpUrl.disconnect(); } catch(IOException e) { } catch(NullPointerException e) { } } return getImageName(fullPath); }