概述
if(StringUtils.isNoneBlank(tplUrl)){
InputStream in = null ;
OutputStream out = null;
try {
String suffix = tplUrl.substring(tplUrl.lastIndexOf(".") + 1);
out = response.getOutputStream();
response.setContentType("application/octet-stream;charset=utf-8");
response.setHeader("Content-Disposition","attachment;filename="+new String(fileName.getBytes(),"iso-8859-1")+"."+suffix);
String orgTplUrl = fileRep.getFileUploadPath() + tplUrl;
URL url = new URL(orgTplUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(3000);
conn.setRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
in = conn.getInputStream();
int b;
while((b=in.read())!= -1){
out.write(b);
}
falg = true;
} catch (Exception e) {
e.printStackTrace();
} finally{
if(in != null){
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(out != null){
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
最后
以上就是缓慢睫毛为你收集整理的下载文件的全部内容,希望文章能够帮你解决下载文件所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复