通过流获取到 char[] ; 将char[] 转换为String;这个过程中怎么指定其编码格式呢。
3条回答 默认 最新
关注 官方有api,,char[] 转string的,,,题主想指定编码,就得先转string,再转byte,在制定编码转回来
因为char字符,自带编码格式,字节的话没编码,,字符自己就有编码,,,有问题还可以追问
【官方api】 public String(char value[], int offset, int count) { if (offset < 0) { throw new StringIndexOutOfBoundsException(offset); } if (count <= 0) { if (count < 0) { throw new StringIndexOutOfBoundsException(count); } if (offset <= value.length) { this.value = "".value; return; } } // Note: offset or count might be near -1>>>1. if (offset > value.length - count) { throw new StringIndexOutOfBoundsException(offset + count); } this.value = Arrays.copyOfRange(value, offset, offset+count); }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决评论 打赏 举报无用 1