自己做一个byte转无符号int的方法如下: private int b2i (int n){ if (n < 0) { n = n + 256; return n; } return n; } 以上用来转换出无符号整数,然后用: Character.toString((char)(b2i(bstr[i]))) 就得到你要的字符啦 依此类推:做一个for循环就可以把bstr数组里面所有的数据转出来了
String(byte[] bytes, String charsetName) Constructs a new String by decoding the specified array of bytes using the specified charset.byte[] getBytes(String charsetName) Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array.
所以才焦头烂额。
最好用StringBuffer这个类
详细用法请看文档
一个是可变长的,一个是定长的。对我来说没有用啊。
private int b2i (int n){
if (n < 0) {
n = n + 256;
return n;
}
return n;
}
以上用来转换出无符号整数,然后用:
Character.toString((char)(b2i(bstr[i])))
就得到你要的字符啦
依此类推:做一个for循环就可以把bstr数组里面所有的数据转出来了
Constructs a new String by decoding the specified array of bytes using the specified charset.byte[] getBytes(String charsetName)
Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array.
String str = rs.getClob("column").getSubString(1,(int)rs.getClob("column").length());
byte[] bytes=...;
StringBuffer buf = new StringBuffer();
for(int i = 0; i < bytes.length; i++){
byte b= bytes[i];
if(b < 0)
buf.append("["+b+"]");
else
buf.append(b);
}