导航:首页 > 编程语言 > java下载response

java下载response

发布时间:2024-12-18 08:57:58

java文件下载不显示中文文件名,

//下载
response.setContentType("application/x-msdownload");
String filename = "测试.zip";
String iso_filename = SysParameter.parseGBK(filename);
response.setHeader("Content-Disposition",
"attachment;filename=" + iso_filename);

ServletOutputStream op = response.getOutputStream();
op.write(ab);
op.flush();
op.close();

SysParameter.parseGBK 方法:
// 将GBK字符转化为ISO码
public static String parseGBK(String sIn) {
if (sIn == null || sIn.equals(""))
return sIn;
try {
return new String(sIn.getBytes("GBK"), "ISO-8859-1");
} catch (UnsupportedEncodingException usex) {
return sIn;
}
}

② java如何实现下载弹出的对话框

Java实现点击下载文件的时候,弹出“另存为”对话框,选择保存位置,然后下载,代码如下:

publicvoiddownLoad(StringfilePath,HttpServletResponseresponse)
throwsException{
System.out.println("filePath"+filePath);
Filef=newFile(filePath);
if(!f.exists()){
response.sendError(404,"Filenotfound!");
return;
}
BufferedInputStreambr=newBufferedInputStream(newFileInputStream(f));
byte[]buf=newbyte[1024];
intlen=0;
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition","attachment;filename="+f.getName());
OutputStreamout=response.getOutputStream();
while((len=br.read(buf))>0)out.write(buf,0,len);
br.close();
out.close();
}
阅读全文

与java下载response相关的资料

热点内容
架构师需要阅读的源码 浏览:475
ch编译器 浏览:448
java必须自己写一个编译器吗 浏览:936
如何制作androidrom 浏览:468
单片机万能板怎么写入程序 浏览:18
迈锐宝xl压缩比 浏览:339
靠算法买彩票 浏览:497
程序员考核d 浏览:239
自助游中国pdf 浏览:746
安卓p40是什么手机 浏览:87
24cxx编程器 浏览:591
阴阳师如何查看哪个服务器有ID 浏览:316
公务员照片压缩 浏览:458
编译的时候怎么找未定义的函数 浏览:352
有什么我的世界服务器 浏览:306
服务器亮绿灯是什么意思 浏览:637
python画的图如何保存高清版 浏览:499
10的搭接还用加密吗 浏览:373
bytedance这个文件夹是什么意思呢 浏览:596
算法站的客体 浏览:84