Java字符编码(US_ASCII, ISO_8859_1(Lantin1), UTF-8, UTF-16, UTF-32)

1. 测试代码

package demo.java.security;

import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.ReflectUtil;

import java.math.BigInteger;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

public class UTF8Test {
    public static void main(String[] args) throws Exception {
//        String str = "ABC"; // US_ASCII // 0000—007F 基本拉丁字母
//        String str = "©"; // ISO_8859_1, Latin1 // 0080—00FF 拉丁文补充1
        String str = "中"; // 中文 - 基本平面 (中)
//        String str = "\uD869\uDEA5"; // 中文 - 辅助平面 (𪚥)

        System.out.println(str);

         // 系统默认字符集是UTF-8
        System.out.println(Charset.defaultCharset());

        // JVM内部String用的编码是 UTF_16 + ISO_8859_1
        System.out.println("内部编码\t\t\t\t" + toHex((byte[]) ReflectUtil.getFieldValue(str, "value")));

        // US_ASCII 和 ISO_8859_1(Latin1), 不支持中文, 所以显示为 3F(?)
        System.out.println("标准编码(US_ASCII)\t\t " + toHex(str.getBytes(StandardCharsets.US_ASCII)));
        System.out.println("标准编码(ISO_8859_1)\t\t " + toHex(str.getBytes(StandardCharsets.ISO_8859_1)));

        /**
         * UTF-8, UTF-16, UTF-32 显示
         * [Unicode字符百科] https://unicode-table.com/cn/4E2D/
         */
        System.out.println("标准编码(UTF-8)\t\t " + toHex(str.getBytes(StandardCharsets.UTF_8)));
        System.out.println("标准编码(UTF-16BE)\t " + toHex(str.getBytes(StandardCharsets.UTF_16BE)));
        System.out.println("标准编码(UTF-16LE)\t " + toHex(str.getBytes(StandardCharsets.UTF_16LE)));
        System.out.println("标准编码(UTF-32BE)\t " + toHex(str.getBytes("UTF_32BE")));
        System.out.println("标准编码(UTF-32LE)\t " + toHex(str.getBytes("UTF_32LE")));
    }

    private static String toHex(byte[] bytes) {
//        return new BigInteger(1, bytes).toString(16);
        return HexUtil.encodeHexStr(bytes);
    }
}

2. 测试效果

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
win7 安装Opentaps 1.5 以下是在安装前的一些文件修改和操作 1)修改framework\entity\config\entityengine.xml 文件 a)把<delegator name="default" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" distributed-cache-clear-enabled="false"> <group-map group-name="org.ofbiz" datasource-name="localderby"/>(53、54行)的localderby修改为localmysql b)把<datasource name="localmysql" 段(314行)做以下修改: table_tye="InnoDB" 修改为 Engine="InnoDB" character-set="lantin1" 修改为 character-set="utf8" collate="lantin1_general_cs" 修改为 collate="utf8_general_ci" jdbc-uri="jdbc:mysql://127.0.0.1/ofbiz?autoReconnect=true&useOldAliasMetadataBehavior=true" 中的ofbiz修改为opentaps //opentaps为创建的数据库名字 jdbc-username="ofbiz" 和 jdbc-password="ofbiz" 中的ofbiz修改为mysql上创建了的用户名和密码 c)修改build.properties文件,把里面的内存值减小一半(如果内存是4G以上就不用修改了) d)把 \framework\webapp\src\org\ofbiz\webapp\controlfor\ConfigXMLReader.java文件中的 81行 for (String a : url.toString().split(File.seperator)) { 中File.seperator修改为 "/"   e)打开\opentaps\opentaps\opentaps-common\build-aspects.xml文件,将以下三行注释掉 <jar jarfile="${ofbiz.dir}/framework/entity/build/lib/ofbiz-entity.jar" update="true" basedir="${build.dir}/classes/" includes="META-INF/aop.xml" /> <jar jarfile="${ofbiz.dir}/framework/common/build/lib/ofbiz-common.jar" update="true" basedir="${build.dir}/classes/" includes="META-INF/aop.xml" /> <jar jarfile="${ofbiz.dir}/applications/order/build/lib/ofbiz-order.jar" update="true" basedir="${build.dir}/classes/" includes="META-INF/aop.xml" /> f) 如果Mysql 版本太低,会导致表无法创建, 解决方法如下   framework\entity\src\org\ofbiz\entity\jdbc下的DatabaseUtil.java   将createTable方法中的    if (UtilValidate.isNotEmpty(this.datasourceInfo.tableType)) { sqlBuf.append(" TYPE "); sqlBuf.append(this.datasourceInfo.tableType); }   中的TYPE修改为ENGINE

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值