首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

处理中文文件名上载有关问题

2012-11-03 
处理中文文件名下载问题??String filePath super.realPath + URLDecoder.decode(URLDecoder.decode((Str

处理中文文件名下载问题

?

?String filePath = super.realPath + URLDecoder.decode(URLDecoder.decode((String) form.get("openFilePath"),?'UTF-8'),?'UTF-8');

?? ? ? ?File dFile = new File(filePath);

?? ? ? ?FileInputStream fis = new FileInputStream(dFile);

?

?? ? ? ?this.getResponse().reset();

?? ? ? ?this.getResponse().setContentType("Application/Octet-Stream");

?? ? ? ?String fileName = URLDecoder.decode(URLDecoder.decode((String) form.get("openFileName"), KamsConst.SERVER_ENCODING), KamsConst.SERVER_ENCODING);

?? ? ? ?this.getResponse().setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, 'UTF-8'));

?? ? ? ?OutputStream os = this.getResponse().getOutputStream();

?

?? ? ? ?byte[] b = new byte[1024];

?? ? ? ?int real = fis.read(b);

?? ? ? ?while (real > 0) {

?? ? ? ? ? ?os.write(b, 0, real);

?? ? ? ? ? ?real = fis.read(b);

?? ? ? ?}

?? ? ? ?os.close();

?? ? ? ?fis.close();

?? ? ? ?return RESULT_SUCCESS;

热点排行