|
@@ -11,6 +11,7 @@ import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStream;
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
@@ -24,6 +25,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.IOUtils;
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
+import org.apache.commons.lang.StringEscapeUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
@@ -106,7 +108,10 @@ public class FileDisposeUtil {
|
|
//设置Content-Disposition,名称强制为UTF-8
|
|
//设置Content-Disposition,名称强制为UTF-8
|
|
//String fileEncode = System.getProperty("file.encoding");
|
|
//String fileEncode = System.getProperty("file.encoding");
|
|
//response.setHeader("Content-Disposition", "attachment;filename="+new String(filename.getBytes(fileEncode),"UTF-8"));
|
|
//response.setHeader("Content-Disposition", "attachment;filename="+new String(filename.getBytes(fileEncode),"UTF-8"));
|
|
- response.setHeader("Content-Disposition", "attachment;filename="+URLEncoder.encode(filename,"UTF-8"));
|
|
|
|
|
|
+ //response.setHeader("Content-Disposition", "attachment;filename="+URLEncoder.encode(filename,"UTF-8"));
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename="+URLEncoder.encode(filename,"UTF-8")
|
|
|
|
+ .replace("%28", "(")
|
|
|
|
+ .replace("%29", ")"));
|
|
// 设置强制下载不打开
|
|
// 设置强制下载不打开
|
|
response.setContentType("application/octet-stream;charset=utf-8");
|
|
response.setContentType("application/octet-stream;charset=utf-8");
|
|
//读取目标文件,通过response将目标文件写到客户端
|
|
//读取目标文件,通过response将目标文件写到客户端
|
|
@@ -242,8 +247,13 @@ public class FileDisposeUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
|
- System.out.println(System.getProperty("sun.jnu.encoding"));
|
|
|
|
- System.out.println(System.getProperty("file.encoding"));
|
|
|
|
|
|
+ public static void main(String[] args) throws UnsupportedEncodingException {
|
|
|
|
+// System.out.println(System.getProperty("sun.jnu.encoding"));
|
|
|
|
+// System.out.println(System.getProperty("file.encoding"));
|
|
|
|
+ String fileName = "梦想(2)";
|
|
|
|
+
|
|
|
|
+ System.out.println(URLEncoder.encode(fileName,"UTF-8")
|
|
|
|
+ .replace("%28", "(")
|
|
|
|
+ .replace("%29", ")"));
|
|
}
|
|
}
|
|
}
|
|
}
|