字符编码转换问题

来源:互联网 发布:筛选股票数据专门网站 编辑:程序博客网 时间:2024/04/30 00:11
/** *//**
     * 字符串编码转换的实现方法
     * @param str    待转换的字符串
     * @param newCharset    目标编码
     */
    public String changeCharset(String str, String newCharset) throws UnsupportedEncodingException{
        if(str != null) {
            //用默认字符编码解码字符串。与系统相关,中文windows默认为GB2312
            byte[] bs = str.getBytes();
            return new String(bs, newCharset);    //用新的字符编码生成字符串
        }
        return null;
    }
原创粉丝点击