String
public String(byte[] bytes,
              int offset,
              int length,
              String charsetName)
       throws UnsupportedEncodingException
Constructs a new String by decoding the specified subarray of bytes using the specified charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the subarray. 
The behavior of this constructor when the given bytes are not valid in the given charset is unspecified. The CharsetDecoder class should be used when more control over the decoding process is required. 
Parameters:
bytes - the bytes to be decoded into characters
offset - the index of the first byte to decode
length - the number of bytes to decode
charsetName - the name of a supported charset 
Throws: 
UnsupportedEncodingException - if the named charset is not supported 
IndexOutOfBoundsException - if the offset and length arguments index characters outside the bounds of the bytes array 
NullPointerException - if charsetName is null
Since: 
JDK1.1 

解决方案 »

  1.   

    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.应该是将一个byte数组转换为String吧
    不过上面也说了,这是一个不推荐使用的api,因为This method does not properly convert bytes into characters
      

  2.   

    使用例子如下:public class GetASCII{
        public static void main(String[] args){        
    byte b[] = {55,56,57,54,53};
    String tmpstr = new String(b,0,0,b.length);
    System.out.println(tmpstr);
    }
    }
      

  3.   

    byte b[] = {'a','b','c'};
    String tmpstr = new String(b,0,0,b.length);这个时候tmpstr="abc";