String(byte[] ascii, int hibyte, int offset, int count) 
          Deprecated. This method does not properly convert bytes into characters. As of JDK 1.1, the preferred way to do this is via the String constructors that take a charset name or that use the platform's default charset. 
String(byte[] bytes, int offset, int length, String charsetName) 
          Constructs a new String by decoding the specified subarray of bytes using the specified charset. 

解决方案 »

  1.   

    look up the APIs docs from sun's web
      

  2.   

    把比特流b4的第一个字节重新实例化bytes2字符集的字符串desFile
      

  3.   

    比如说我本来有一串字符串是从IE提交到服务器端的,从IE上提交的时候默认的字符集
    是ISO8859-1,我要把这个字符串存到数据库里去,我的数据库采用的是Shift_JIS码。
    于是我发现存进去后原来好端端的字符串都变成了"???",我就要转码。于是调用
    String str2 = String(str1.getBytes("ISO8859-1"), 0, str1.length, "Shift_JIS");
    第2个参数表示我从第几个byte开始转,第3个参数表示要转多少个byte。
    够清楚了吗?
      

  4.   

    先看这个 public String(byte[] bytes,String charsetName),如果byte[] bytes = "你好".getBytes("gb2312");然后用String s = new String(b,"gb2312");就能返回"你好";
    如果用String s = new String(b,0,2,"gb2312");则返回"你",第2-3个参数说明返回从开头(0)开始的2各字节的解码(一个汉字两个字节);用String s = new String(b,"iso8859-1");则返回乱码,因为加密字符集与解密字符集不一致。
      

  5.   

    byte buffer[]=new byte[256];
    FileInputStream fileInput=new FileInputStream("d:\\prg\\test\\1.txt");
    int a=fileInput.read(buffer,0,256);
    //这一行,为什么要把buffer转换成整型??
    String str=new String(buffer,0,0,a);
    //String函数的中参数0,0的意思是:把buffer的第零个字节转换吗?
    System.out.println(str);