想要访问一个地址,然后把下载的东西放到一个文件夹里,求思路,有需要用的类最好! java IO流上传,下载文件。好好看看。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 HttpURLConnection urlConn = null; url = new URL(strUrl); urlConn = (HttpURLConnection) url.openConnection(); urlConn.setConnectTimeout(1000 * 20); InputStreamReader in = new InputStreamReader(urlConn.getInputStream());获取到inputstream,你就写到你的文件夹下去 String filePath=request.getRealPath("/.."); String filename = "total.zip"; File fileLoad = new File(filePath, filename); FileInputStream in = null; // 输入流 OutputStream out = response.getOutputStream(); byte b[] = new byte[1024]; try { response.setContentType("application/x-msdownload;"); response.setHeader("Content-disposition", "attachment; filename=" + new String(filename.getBytes("UTF-8"), "UTF-8")); // download the file. in = new FileInputStream(fileLoad); int n = 0; while ((n = in.read(b)) != -1) { out.write(b, 0, n); } } catch (Throwable e) { e.printStackTrace(); } finally { try { in.close(); out.close(); } catch (Throwable e) { e.printStackTrace(); } } JAVA怎么一次性读取串口内所有的数据 Hibernate事务处理问题 类似于json格式的字符串怎么解析? 如何得到hibernate结果集的元数据 hibernate中什么情况下要用到继承呢?实际当中还有两个表是继承关系吗? 连接池问题,解决就给分?? java 从数据库中导出大量数据 生成txt文件,内存溢出 有关JSF(Java Server Faces)的测试问题 菜菜菜菜菜菜菜菜菜菜菜菜菜菜菜鸟问题! 关于UML图 SpringMVC 2.5 DEMO js如何搞这个
url = new URL(strUrl);
urlConn = (HttpURLConnection) url.openConnection();
urlConn.setConnectTimeout(1000 * 20);
InputStreamReader in = new InputStreamReader(urlConn.getInputStream());
获取到inputstream,你就写到你的文件夹下去
String filename = "total.zip";
File fileLoad = new File(filePath, filename); FileInputStream in = null; // 输入流
OutputStream out = response.getOutputStream();
byte b[] = new byte[1024];
try {
response.setContentType("application/x-msdownload;");
response.setHeader("Content-disposition", "attachment; filename="
+ new String(filename.getBytes("UTF-8"), "UTF-8"));
// download the file.
in = new FileInputStream(fileLoad);
int n = 0;
while ((n = in.read(b)) != -1) {
out.write(b, 0, n);
} } catch (Throwable e) {
e.printStackTrace();
} finally {
try {
in.close();
out.close();
} catch (Throwable e) {
e.printStackTrace();
}
}