如题,中文文件名乱码该如何解决? if (uploads != null)
        {
         File dir = new File(dirName);
         if(!dir.isDirectory())
         dir.mkdirs();
            int i = 0;
            for (; i < uploads.size(); i++)
            {
                java.io.InputStream is = new java.io.FileInputStream(uploads.get(i));
                java.io.OutputStream os = new java.io.FileOutputStream(
                 dirName + }new String(fileNames.get(i).getBytes("gb2312"),"iso-8859-1"));
                byte buffer[] = new byte[8192];
                int count = 0;
                while ((count = is.read(buffer)) > 0)
                {
                    os.write(buffer, 0, count);
                }
                os.close();
                is.close();
            }
        

解决方案 »

  1.   

    要在struts.properties 文件中要配置一个 信息struts.i18n.encoding = gbk
      

  2.   

    在struts2.0中,struts.properties 这个文件在哪儿?
      

  3.   

    放在 classpath 下面 相对于在myeclipse 工程的src下 就可以了
      

  4.   

    没有呀 ,只有一个struts.xml
      

  5.   

    struts上传文件用的是gbk编码方式,所以将文件名转码就可以。 new String(filename.getBytes("GBK"),"UTF-8"); 
    这里有个问题,网上经常有人将编码格式改称gbk或者是gb2312,
    不过为了国际化和通用性,我建议还是用UTF-8编码格式。
    毕竟现在的开发工具大部分都是国外的,对UTF-8的支持到位。
    同时国际化也方便。 你这里struts上传文件用的是gb2312编码方式,那你就
    new String(filename.getBytes("GB2312"),"UTF-8");
      

  6.   

    还是不行呀,我在struts.xml中加了<constant name="struts.i18n.encoding" value="GBK"/>
    代码里改成 java.io.OutputStream os = new java.io.FileOutputStream(
                     dirName + new String(fileNames.get(i).getBytes("GBK"),"utf-8"));
    中文文件名还是?