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);
    }
    }


    编辑器加载中...

  • 相关阅读:
    软件工程个人作业02
    第三周学习进度条
    《构建之法》阅读笔记01
    第二周学习进度条
    软件工程个人作业01
    大道至简第三章读后感
    动手动脑课后实践
    JAVA数字想加并输出
    大道至简第二章读后感
    大道至简读后感
  • 原文地址:https://www.cnblogs.com/BigIdiot/p/2282319.html
Copyright © 2011-2022 走看看