使用多线程通过HttpURLConnection 下载文件,也没有报错,老是出现下载下来的文件比实际的小,然后提示打不开。有什么好的方法没?谢谢
解决方案 »
- MyEclipse +Tomcat部署调试Strust2的问题
- 在glassfish上建的数据源,为什么initialcontext.lookup("java:comp/env/..");这个方法不成功?
- Spring 2.5 与 JPA 整合的问题
- 请问谁下载了struts2.18并解压成功的啊?我下载两次都是解压失败
- 为什么要 配置数据源???
- 请问在tomcat中如何配置web.xml,我怎么不行呀
- cmp中,自己创建find问题
- 在哪里可以找到一个比较完整的j2ee应用例子下载?
- (80分)如何把JAVA程序制作成安装程序???
- 在struts.xml中使用result type="json" 如何在ajax中获得值
- 寻求建议
- 怎么自动辨别用户ip是电信,网通或是移动铁通及其他
贴代码。
String password)
throws ApplicationException {
FileOutputStream out = null;
BufferedInputStream in = null;
byte[] buf = new byte[BUFFER_SIZE];
int size = 0;
try {
connectServer(destUrl);
in = new BufferedInputStream(httpUrl.getInputStream());
out = new FileOutputStream(fullName);
while ((size = in.read(buf)) != -1) {
out.write(buf, 0, size);
}
out.flush();
} catch (IOException e) {
throw new ApplicationException("通过HTTP下载文件出现异常:"
+ e.getMessage());
} finally {
if ( in != null) { try { in.close(); } catch (IOException ex) {}}
if ( out != null) { try { out.close(); } catch (IOException ex) {}}
if(httpUrl != null) httpUrl.disconnect();
}
}