zoukankan      html  css  js  c++  java
  • JAVA_字符集

    package com.kk.review;

    import java.io.IOException;
    import java.io.UnsupportedEncodingException;
    import java.nio.charset.Charset;
    import java.util.Map;
    import java.util.Properties;



    public class CharSetTest {
    public static void main(String[] args)throws IOException{
    getAllSupportedCharSet();
    getJVMProperties();
    charSetConvertion();
    }

    /**
    * 获取本地jvm支持的编码
    *
    */
    static void getAllSupportedCharSet() {
    Map<String,Charset> sets=Charset.availableCharsets();
    for(String str:sets.keySet()){
    System.out.println(str);
    }
    }

    /**
    * 获取本地jvm的属性,其中包括文件系统的默认格式
    *
    */
    static void getJVMProperties(){
    Properties jvmProperties=System.getProperties();
    jvmProperties.list(System.out);
    }

    /**
    * 控制台打印乱码现象
    *
    @throws UnsupportedEncodingException
    */
    static void charSetConvertion()throws UnsupportedEncodingException{
    String str=new String("哈哈".getBytes(),"iso-8859-1");
    System.out.println(str);//打印乱码,因为console是与本地文件系统格式一样的,我的是GBK
    str=new String(str.getBytes("iso-8859-1"),"GBK"); //将iso-8859-1编码转成GBK编码,这样打印出来的就不是乱码了
    System.out.println(str);
    }
    }


    编辑器加载中...

  • 相关阅读:
    Shiro认证过程?
    使用过Redis做异步队列么,你是怎么用的?
    使用 Spring Boot有什么好处
    Spring Boot、Spring MVC 和 Spring 有什么区别?
    es
    python并发编程
    Go基础05
    Go04基础
    Go03基础
    Go基础02
  • 原文地址:https://www.cnblogs.com/BigIdiot/p/2282319.html
Copyright © 2011-2022 走看看