• 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;

    }

     

    }

     

     

     

     

  • 相关阅读:
    iOS 循环引用 委托 (实例说明)
    【iOS】自动引用计数 (循环引用)
    有关UITableviewCell 重用内存 内部解析
    通用的类->可直接存储的Dictionary,可以被JSON或NSUserDefaults
    ipa 发布到stroe
    根据当前登录域账号 获取AD用户姓名和所在OU目录
    ASP.NET MVC 操作AD 获取域服务器当前用户姓名和OU信息
    各种图标 资源下载
    【赚】cocos2d-x学习资源汇总(持续更新。。。)
    ios网络层优化深入浅出
  • 原文地址:https://www.cnblogs.com/attilax/p/15198793.html
Copyright © 2020-2023  润新知