//用来对写文件的时候重编码
  public static String setFileEncoding(String data1)
      throws Exception
  {    String charset = "GB2312";
    String newset = "ISO8859_1";    byte[] str = data1.getBytes(charset);    String data = new String(str,newset);    return data;
  }用这个函数,肯定没错。给分,呵呵!!

解决方案 »

  1.   

    gb2312也试过了
    或者
    String str = new String(radioORcheckbox.getBytes("GBK"),"ISO8859_1");
    也试过了。
    我说的是读文件
    写文件时转换字符后,中文没有乱码;
    只是在读文件时,中文出现乱码。
      

  2.   

    总有一款适合你String aa = file.readLine();
    System.out.println("---1---" + aa);
    System.out.println("---2---" + new String(aa.getBytes(),"UTF-8"));
    System.out.println("---3---" + new String(aa.getBytes(),"iso8859-1"));
    System.out.println("---4---" + new String(aa.getBytes(),"gb2312"));System.out.println("===5===" + new String(aa.getBytes("gb2312"), "utf-8"));
    System.out.println("===6===" + new String(aa.getBytes("gb2312"), "iso8859-1"));

    System.out.println("===7===" + new String(aa.getBytes("utf-8"), "gb2312"));
    System.out.println("===8===" + new String(aa.getBytes("utf-8"), "iso8859-1"));

    System.out.println("===9===" + new String(aa.getBytes("iso8859-1"), "gb2312"));
    System.out.println("===10==" + new String(aa.getBytes("iso8859-1"), "utf-8"));
      

  3.   

    这样处理:
    加这么一个处理函数:
    <%! //处理中文字符串的方法
     public String getString(String s)

     if(s==null)
       {s="";}
     try
       {
         byte b[]=s.getBytes("ISO-8859-1");
         s=new String(b);
       }
     catch(Exception e)
      {}
     return s;
    }调用:
    <% String customer=(String)session.getAttribute("customer");
    customer=getString(customer);
    %>
      

  4.   

    不行啊
    这个应该与服务器的设置JSP编码有关
    尝试打出服务器当前的属性
    其中
    sun.io.unicode.encoding:UnicodeBig
    是不是应该将page 里的charset设为utf-8
    但是这样报错。
      

  5.   

    <%@ page contentType="text/html; charset=GB2312" %>
    在Jsp前面加上字符集编码声明。
      

  6.   

    除了在JSP中声明:<%@ page contentType="text/html; charset=GB2312" %>
    还必须保证你的servlet的字符编码也是GB2312,在../web.xml里设置。
      

  7.   

    为什么在jsp中读?
    bean中也会?
    不会吧.读出应该不会出错的.是页面解析时出错的(未转换)