zoukankan      html  css  js  c++  java
  • atitit.Atitit.检测文本文件的编码 java  与php版  。Net

    atitit.Atitit.检测文本文件的编码 java  php版  。Net

     

     

    检测编码原理

    Utf8》》gbk

    在此转会gbk》》utf

     

     

     

     

    工具检测编码

    不能使用load来检测编码..

     

     

    要是txt是 gbk使用notepad++ load as utf8 三正常的...

    Load as gbk 却乱码了...

     

     

    Editplusok...

     

     

    不过.要是文件是utf8.. Editplus  load as gbk 显示是正常的..所以,不能使用load来检测编码..

     

    作者:: 绰号:老哇的爪子 ( 全名::Attilax akbar al rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 ) 汉字名:艾龙,  EMAIL:1466519819@qq.com

    转载请注明来源: http://blog.csdn.net/attilax

     

    使用convert来检测编码

    使用convert来检测编码..docu>>file encode >>convet encode  显示编码确认框..这个走十恰当的的编码...

     

    也可以使用notepad的另存为来检测..

     

    编程api方式检测编码

    public class EncodeCheckor {

     

    public static void main(String[] args) {

    // TODO Auto-generated method stub

    String f = pathx.classPath() + "/aaaNaming/names.txt";

    System.out.println(getEncode(f));

    }

     

    private static String getEncode(String f) {

    // TODO Auto-generated method stub

    String t = filex.read(f);

    String $zh = t;

    ;

    String $s1 = iconv("UTF-8""gb2312"$zh);

    String $s2 = iconv("gb2312""UTF-8"$s1);

    if ($s2 .equals( $zh)) {

    return "utf-8";

    // if utf code , convert2 gbk mode

    return "gbk";

    }

     

    private static String iconv(String encode1, String encode2, String str) {

    byte[] temp = null;

    try {

    temp = str.getBytes(encode1);

    catch (UnsupportedEncodingException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    }// 这里写原编码方式

    String newStr = null;

    try {

    newStr = new String(tempencode2);

    catch (UnsupportedEncodingException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    }// 这里写转换后的编码方式

     

    return newStr;

    }

     

    }

     

     

     

     

  • 相关阅读:
    一种可以避免数据迁移的分库分表scale-out扩容方式
    ZooKeeper快速搭建
    ZooKeeper典型应用场景一览
    基于 Quartz 开发企业级任务调度应用
    mac安装dart环境配置及中途的错误解决
    Android Studio3.3打包报错AAPT2 process unexpectedly exit. Error output:
    android在App应用内打开word、xls、pdf等office文档(基于腾讯tbs)
    android分渠道打包,监测日活量统计(基于友盟SDK)
    PHP环境搭建-Windows系统下PHP环境搭建
    使用bugly热更新时自定义升级弹窗的UI样式
  • 原文地址:https://www.cnblogs.com/attilax/p/5963567.html
Copyright © 2011-2022 走看看