首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

关于上载

2012-09-09 
关于下载private static void downloadFile(String url, File outputFile) {?? try {?? ? ? URL u new U

关于下载

private static void downloadFile(String url, File outputFile) {?
? try {?? ? ? URL u = new URL(url);?
? ? ? URLConnection conn = u.openConnection();?
? ? ? int contentLength = conn.getContentLength();?
?
? ? ? DataInputStream stream = new DataInputStream(u.openStream());?
?
? ? ? ? byte[] buffer = new byte[contentLength];?
? ? ? ? stream.readFully(buffer);?
? ? ? ? stream.close();?
?
? ? ? ? DataOutputStream fos = new DataOutputStream(new FileOutputStream(outputFile));?
? ? ? ? fos.write(buffer);?
? ? ? ? fos.flush();?
? ? ? ? fos.close();?
? } catch(FileNotFoundException e) {?
? ? ? return; // swallow a 404?
? } catch (IOException e) {?
? ? ? return; // swallow a 404?
? }?
}?

热点排行