📄 charchange.java
字号:
package Translate;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
public class charchange {
public static final String GBK = "GBK";
public static final String EUC_KR = "EUC-KR";
public String toEUC_KR(String str) throws UnsupportedEncodingException
{
return this.changeCharset(str, EUC_KR);
}
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;
}
public String changeCharset(String str, String oldCharset, String newCharset) throws UnsupportedEncodingException
{
if(str != null)
{
//用源字符编码解码字符串
byte[] bs = str.getBytes(oldCharset);
return new String(bs, newCharset);
}
return null;
}
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
charchange c=new charchange();
String str="窍捞咯";
System.out.println("韩文乱码: "+str);
String KR=c.toEUC_KR(str);
System.out.println("转换成韩文: "+KR);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -