野花一片 2017-11-02 03:01 采纳率: 33.3%
浏览 3040
已采纳

java中如果将char[] 转string 并指定编码格式

通过流获取到 char[] ; 将char[] 转换为String;这个过程中怎么指定其编码格式呢。

  • 写回答

3条回答 默认 最新

  • 鼠晓 博客专家认证 2017-11-02 07:12
    关注

    官方有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);
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型