zoukankan      html  css  js  c++  java
  • IO 流中编码和解码问题

    编码表

    • ASCII : American Standard Code for Information Interchange
      • 使用一个字节的 7 位可以表示
    • ISO8859-1 : 拉丁码表. 欧洲码表
      • 使用一个字节的 8 位表示
    • GBK : 中文编码表
    • Unicode : 国际标准码, 融合了多种文字
      • 所有文字都用两个字节来表示
    • UTF-8 :最多用三个字节来表示一个字符
    // 示例: 字符串的编解码
    
        // 字符串转换成字节数组, 编码
        String str = "你好";
    
        // 使用 GBK 编码, -60 -29 -70 -61
        byte[] buf = str.getBytes("GBK");
    
        // 使用 utf-8 编码, -28 -67 -96 -27 -91 -67
        byte[] buf1 = str.getBytes("utf-8");
    
        // 将字节数组转换成字符串
        String s1 = new String(buf,"GBK");
    
        String s2 = new String(buf1,"utf-8");
    


    **参考资料** - [JavaSE 基础视频(毕向东)](https://www.bilibili.com/video/av3129288/#page=14) - [JDK 1.6 中文文档](http://tool.oschina.net/apidocs/apidoc?api=jdk-zh)
  • 相关阅读:
    Python基础-序列化模块
    dubbox
    小型供销系统
    MyBatis与SpringBoot整合案例(一)
    SpringBoot第二节
    SpringBoot第一节
    Dubbo案例SSM整合
    Dubbo生产者和消费者
    Zookeeper实战分布式锁
    Zookeeper Watcher和选举机制
  • 原文地址:https://www.cnblogs.com/linkworld/p/7519599.html
Copyright © 2011-2022 走看看