import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class DownLoadUtils {
public static String getFileName(String agent, String fileName) throws UnsupportedEncodingException {
if (agent.contains("MSIE")) {
// IE浏览器
fileName = URLEncoder.encode(fileName, "utf-8");
fileName = fileName.replace("+", " ");
} else if (agent.contains("Firefox")) {
// 火狐浏览器
// BASE64Encoder base64Encoder = new BASE64Encoder();
// filename = "=?utf-8?B?" + base64Encoder.encode(filename.getBytes("utf-8")) + "?=";
fileName = new String(fileName.getBytes("gbk"), "iso8859-1");
} else {
// 其它浏览器
fileName = URLEncoder.encode(fileName, "utf-8");
}
return fileName;
}
}
|
|