String是采用16位的编码方式吗

解决方案 »

  1.   

    “123”在内存中用6字节表示,用ANSI写到文件里是3字节,从文件读3字节得到长度为3的字节数组,再转为字符串后是6字节
    可以看一下String的源码    public String(byte bytes[], int offset, int length, Charset charset) {
            if (charset == null)
                throw new NullPointerException("charset");
            checkBounds(bytes, offset, length);
            char[] v = StringCoding.decode(charset, bytes, offset, length);
            this.offset = 0;
            this.count = v.length;
            this.value = v;
        }