我是靠谱客的博主 缓慢睫毛,这篇文章主要介绍下载文件,现在分享给大家,希望可以做个参考。

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();
}
}
}
}

最后

以上就是缓慢睫毛最近收集整理的关于下载文件的全部内容,更多相关下载文件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(75)

评论列表共有 0 条评论

立即
投稿
返回
顶部