今天做了一个URL下载的程序,发现文件名是%BD%CC%B3%CC 这种类型的,不知道怎么解析,后面查了下发现是GBK内码。。
请问下怎么把GBK内码转换成中文呢?

解决方案 »

  1.   

    用过滤器吧,比较方便,import java.io.IOException;
    import javax.servlet.*; public class ChangeCharsetFilter implements Filter {     protected String encoding = null;/////要制定的编码,在web.xml中配置    protected FilterConfig filterConfig = null;
        public void destroy() {
        this.encoding = null;
        this.filterConfig = null;}
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
        if (request.getCharacterEncoding() == null){
        String encoding = getEncoding();////得到指定的编码名字
        if (encoding != null)
        request.setCharacterEncoding(encoding);////设置request的编码
    }
        chain.doFilter(request, response);///有机会执行下一个filter
    }
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
        this.encoding = filterConfig.getInitParameter("encoding");///得到在web.xml中配置的编码
    } protected String getEncoding() {
        return (this.encoding);///得到指定的编码
        } }然后在web.xml中配置:<filter>
    <filter-name>SetCharacterEncoding</filter-name>
    <filter-class>ChangeCharsetFilter </filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>GBK</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>SetCharacterEncoding</filter-name>
    <url-pattern>/*</url-pattern>
      </filter-mapping>
      

  2.   

    额。。不是中乱码问题。。那种什么new String(a.getByte("ISO8859_1"),"GBK")的不行