public class Test{
public static void main(String[] args)throws Exception {
byte bytes[] = new byte[256];
for (int i = 0; i < 256; i++)
bytes[i] = (byte)i;
String str = new String(bytes)
//String str = new String(bytes,"iSO-8859-1")
for (int i = 0, n = str.length(); i < n; i++)
System.out.println((int)str.charAt(i) + " ");
}
}
此程序演示了String(byte [ ])和String(byte[ ],CharSet charset)用法,要想打印出0-255,需要指定字符集。因为中文操作
系统默认字符集为gbk。