In many cases, we write the program will be written to UTF-8 code, can be downloaded file set filename when it is counterintuitive, even set the encoding format for iso8859-1, the code is as follows (in English words do not need to deal with this): Java code Response.setheader ("Content-disposition", "attachment; Filename= "+ New String (" Chinese filename ". GetBytes (" Utf-8 ")," iso8859-1 "));
Extract the core point, Filename=new String ("Chinese filename". GetBytes ("Utf-8"), "iso8859-1");
First of all, why use iso8859-1 encoding, this is mainly due to the HTTP protocol, HTTP header requires its content must be iso8859-1 encoding, so we will eventually encode it as a iso8859-1 encoded string;
But why not use the "Chinese filename" directly in front of the GetBytes ("iso8859-1"); Such a code. Because ISO8859-1 encoded in the Code table, there is no Chinese characters, of course, can not pass the "Chinese filename". GetBytes ("Iso8859-1"), to get the correct "Chinese filename" in the Iso8859-1 encoding value, so again through the new String () to restore it is impossible to talk about. Therefore, the "Chinese filename". GetBytes ("Utf-8") is used to obtain its byte[] byte, which is encoded in bytes, that is, the new String ("Chinese filename". GetBytes ("Utf-8"), "iso8859-1") Re-compose it into a string and pass it to the browser.
Reference: http://jiapumin.iteye.com/blog/1006144