服务器上面的文件如何进行http下载?
用HTTP下载的话文件得拷到网站目录下,你看看你服务器设置的网站目录在哪里,然后把文件拷过去
补充:
没有HTTP服务器自然是不能使用HTTP下载了,安装个APACHE吧
/
文件下载
/
@RequestMapping("/downloadfile")
public void offLineResponseActiveFile(String resStr, HttpServletResponse response) {
PrintWriter pw = null;
StringBuffer sb = new StringBuffer();
try {
String fileName = "文件名";
responsesetCharacterEncoding("UTF-8");
responsesetContentType("application/x-msdownload");
responseaddHeader("Cache-Control", "no-cache, no-store, must-revalidate");
responseaddHeader("charset", "utf-8");
responseaddHeader("Pragma", "no-cache");
responsesetHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"; filename=utf-8''" + fileName );
sbappend(resStr);
pw = responsegetWriter();
pwwrite(sbtoString());
pwclose();
responseflushBuffer();
} catch (IOException e) {
loggerinfo("下载文件出错");
eprintStackTrace();
if (pw != null) {
pwclose();
}
} finally {
if (pw != null) {
pwclose();
}
}
}
resStr 字段传写入文件里的内容
0条评论