⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 encodingconvert.java

📁 Jaoso新闻文章发布系统 0.9.1final 程序架构: Struts+Spring+Hibernate 主要功能:   ·新闻采用在线编辑器,可以象使用word一样编辑新闻,可简繁
💻 JAVA
字号:
package jaoso.framework.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.UnsupportedEncodingException;


/**
 * @author 边缘孤客 edgeloner@yahoo.com.cn
 * @since 2004-11-30
 */
public class EncodingConvert {
    private static Log log = LogFactory.getLog(EncodingConvert.class);

    public static String gb2iso(String str) {
        if (MyUtils.isBlank(str)) {
            return "";
        }

        String result = "";

        try {
            byte[] tmp = str.getBytes("GBK");
            result = new String(tmp, "ISO8859_1");
        } catch (UnsupportedEncodingException e) {
            log.error("convert gb2iso error: ", e);
        }

        return result;
    }

    public static String gb2utf(String str) {
        if (MyUtils.isBlank(str)) {
            return "";
        }

        String result = "";

        try {
            byte[] tmp = str.getBytes("GBK");
            result = new String(tmp, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            log.error("convert gb2utf error: ", e);
        }

        return result;
    }

    public static String iso2gb(String str) {
        if (MyUtils.isBlank(str)) {
            return "";
        }

        String result = "";

        try {
            byte[] tmp = str.getBytes("ISO8859_1");
            result = new String(tmp, "GBK");
        } catch (UnsupportedEncodingException e) {
            log.error("convert iso2gb error: ", e);
        }

        return result;
    }

    public static String iso2utf(String str) {
        if (MyUtils.isBlank(str)) {
            return "";
        }

        String result = "";

        try {
            byte[] tmp = str.getBytes("ISO8859_1");
            result = new String(tmp, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            log.error("convert iso2utf error: ", e);
        }

        return result;
    }

    public static String utf2gb(String str) {
        if (MyUtils.isBlank(str)) {
            return "";
        }

        String result = "";

        try {
            byte[] tmp = str.getBytes("UTF-8");
            result = new String(tmp, "GBK");
        } catch (UnsupportedEncodingException e) {
            log.error("convert utf2gb error: ", e);
        }

        return result;
    }

    public static String utf2iso(String str) {
        if (MyUtils.isBlank(str)) {
            return "";
        }

        String result = "";

        try {
            byte[] tmp = str.getBytes("UTF-8");
            result = new String(tmp, "ISO8859_1");
        } catch (UnsupportedEncodingException e) {
            log.error("convert utf2iso error: ", e);
        }

        return result;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -