关于java里String

byte bArray[]=new byte[128];
int len=System.in.read(bArray);
username=new String(bArray,0,len-2);
“String(bArray,0,len-2);”括号里的是什么意思啊?
对bArray[]赋值后是不是最后一个也会有一个结束符之类的东西?要不然不会“-2”啊。

第1个回答  2007-03-14
调用String的一个构造函数,该构造函数使用一个byte[]来初始化字符串,并指定从该字节数组的0位置开始,取len-2长度。
第2个回答  2007-03-14
第1句定义一个数组 组长128元素 类型为byte
第2句是取输入字符为数组中的元素
第2句是将数组中的字符从第一个开始 除去最后2个 赋值给username
如果没猜错的话 这个应该是设置权限或者注册中截取的语句本回答被提问者采纳
第3个回答  2007-03-14
生成一个字符串常量。从bArray下标的0到(bArray长度-2)的字符生成串

bArray是一个记录字符ascii码的数组。
第4个回答  2007-03-14
用数组bArray()的第0到第len-2个字节创建一个String

以下是JDK的API 说明
\"
public String(byte[] bytes,
int offset,
int length)
Construct a new String by converting the specified subarray of bytes using the platform\'s default character encoding. The length of the new String is a function of the encoding, and hence may not be equal to the length of the subarray.
Parameters:
bytes - The bytes to be converted into characters
offset - Index of the first byte to convert
length - Number of bytes to convert
Since:
JDK1.1 \"
相似回答