将传入的字节数组转换成指定编码的String返回

    技术2022-05-11  2

    public String decodeStr(byte[] bytes, String charset)    throws BusinessException {    String result = null;    if (bytes != null) {

          if (charset != null && !charset.trim().equals("")) {        try {          result = new String(bytes, charset);        } catch (UnsupportedEncodingException e) {          throw new BusinessException("转换字符编码GB2312失败!原因:不支持字符集 " + charset + " !");        }      } else {        result = new String(bytes);      }

        }    return result;  }


    最新回复(0)