String text=new String(str.getBytes("8859_1"),"gb2312");
                                    ~~~~~~~~iso-8859-1?

解决方案 »

  1.   

    显示汉字
    byte [] out;
     out = txt.getBytes("gb2312"); 
      

  2.   

    loveme_y(老猫),在从上一个页面接收text框里的数据的时候,直接用8859_1应该也可以的,所以应该不是这个问题的啦!
      

  3.   

    guojun_2000_2000(阿刺),你的机器是什么环境?
    我的win32系统的环境是win2000+jdk1.3。
    linux的环境是redhat linux 7.0+jdk1.3。
    但是这应该不是什么问题呀!
      

  4.   

    guojun_2000_2000(阿刺),你的是什么环境?
    为什么我的win2000+jdk1.3总是输出乱玛呢?
      

  5.   

    我也测试过你的代码,一字没改。输出中英文都正常。
    环境:win2k(简体中文版)+JDK1.3
      

  6.   

    关键要看你的文件和环境的编码……
    多试验几次,理解了:String text=new String(str.getBytes("8859_1"),"gb2312");这句的真正处理规则就知道了……
      

  7.   

    StringTokenizer tokenizer=new StringTokenizer(str,",");
    String text=tokenizer.nextToken();
    text=new String(text.getBytes("8859_1"),"GB2312");
      

  8.   

    ouxing(星星):这就奇怪了,为什么我的输出总是乱玛呢?
      

  9.   

    你那个list.txt文件是不是"8859_1"格式的啊。
      

  10.   

    老兄,注意JAVA使用Unicode,要转码才行
    public static String ConvertByte(byte[] bs)
        {
            try
            {
              ByteToCharConverter toChar = ByteToCharConverter.getConverte
    r("Big5"); //GB2132
              return new String(toChar.convertAll(bs));
            }
            catch (Exception e)
            {
              System.out.println(e);
              return "";
            }
        }
      

  11.   

    sigama(聚集),能不能结合我的代码说明一下?
      

  12.   

    以流的方式读进文件,读进的数据就是byte[],然后转码就可以了.
    完整的代码等我写一个给你......
      

  13.   

    package test;import java.net.*;
    import java.io.*;
    import sun.io.ByteToCharConverter;
    import sun.io.ConversionBufferFullException;/**
     * Title:
     * Description:
     * Copyright:    Copyright (c) 2001
     * Company:
     * @author
     * @version 1.0
     */public class ReadHZ {
      public static String ConvertByte(byte[] bs)
        {
            try
            {
              ByteToCharConverter toChar = ByteToCharConverter.getConverter("Big5"); //GB2132
              return new String(toChar.convertAll(bs));
            }
            catch (Exception e)
            {
              System.out.println(e);
              return "";
            }
      }  public static void main(String[] args) {
        String s;
        byte bt;
        byte[] bs = new byte[1024];
        int i=1;    try{
            URL url = new URL("file:///e:/test.txt");
            URLConnection uc = url.openConnection();
            InputStream input = uc.getInputStream();
            bs[0] = (byte)input.read();
            while(true)
            {
              bt = (byte)input.read();
              bs[i] = bt;
              if(bs[i]==bs[i-1]&&bs[i]==(byte)0xff)
              {
                byte[] bs2 = new byte[i-1];
                for(int j=0;j<i-1;j++)
                  bs2[j] = bs[j];
                System.out.println(ReadHZ.ConvertByte(bs2));
                break;
              }
              i++;
            }    }
        catch(java.net.MalformedURLException e)
        {
          System.out
          .println(e.toString());
        }
        catch(java.io.IOException e1)
        {
          System.out.println(e1.toString());
        }  }
    }
      

  14.   

    sihama的代码不好用呀
    我怎么中文显示的是?呢?