Ⅰ java 獲得http下載文件的真實名稱
有兩種獲取鏈接文件名的方法:
第一種:從連接URL,從描述中獲取
比如這種地址:
http://book.booktxt.com/txtbuk/20130421/xuanhuan/2013043601180.rar
Ⅱ 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;
}
}