请问如何判断一个字符产变量是用iso8859-1编码还是用GBK编码? 看看这个http://expert.csdn.net/Expert/topic/989/989888.xml?temp=8.301944E-02 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.*;public class test { public static void main(String[] args) { try{ String str = "中文"; String tmp = ChineseToUnicode(str); String iso = new String(tmp.getBytes("ISO8859_1"),"GBK"); System.out.println("-----"+iso+"---"); String gbk = new String(tmp.getBytes("GBK"),"ISO8859_1"); System.out.println("-----"+gbk+"---"); System.out.println("-----"+tmp+"---"); System.out.println("begin"); if (tmp.equals(gbk)) System.out.println("this is ISO8859_1"); if (tmp.equals(iso)) System.out.println("this is GBK"); }catch(Exception e) { System.out.println(e); } }public static String UnicodeToChinese(String s){ try{ if(s==null||s.equals("")) return ""; String newstring=null; newstring=new String(s.getBytes("ISO8859_1"),"GBK"); return newstring; } catch(UnsupportedEncodingException e) { return s; } } public static String ChineseToUnicode(String s){ try{ if(s==null||s.equals("")) return ""; String newstring=null; newstring=new String(s.getBytes("GBK"),"ISO8859_1"); return newstring; } catch(UnsupportedEncodingException e) { return s; } }} 如果你判断一串char是那种编码的数据,只能依赖对编码特性的了解,而且,比如abc的内码,采用各种编码都一样,所以,你不一定总是能够正确判断。如果,你是想得到本地系统的却省编码形式,直接到jvm的系统变量中取好了,dojsp(月下秋风)提供的那段程序真是在胡扯,而http://expert.csdn.net/Expert/topic/989/989888.xml?temp=8.301944E-02这段程序就更离谱了~ jvm的系统变量的说法不准确,就是缺省的Local中取 谢谢yannqi和dojsp给了我思路,问题解决了。 简单的笔试题 求大神们能够给出代码 Java 绘图问题 Java.Util.Date!!! 请教一个关于构件的问题? copyValueOf(char[]) 和 .toString 有什么区别么? java.lang.NoClassDefFoundError: com/microsoft/sqlserver/jdbc/SQLCollation错误 请问有什么软件可以写JAVA的应用逻辑 一个事件问题,在线等待 oxfordxy 谢谢 你的资料 请你来接分 怎么得到一组radio选定的是哪个?? 感谢 BCB 群 的 阿杜0蛋兄弟帮我解决 Java 字符串比较问题,特此放分。 一个关于树的问题
public class test
{
public static void main(String[] args)
{
try{
String str = "中文";
String tmp = ChineseToUnicode(str);
String iso = new String(tmp.getBytes("ISO8859_1"),"GBK");
System.out.println("-----"+iso+"---");
String gbk = new String(tmp.getBytes("GBK"),"ISO8859_1");
System.out.println("-----"+gbk+"---");
System.out.println("-----"+tmp+"---");
System.out.println("begin");
if (tmp.equals(gbk))
System.out.println("this is ISO8859_1");
if (tmp.equals(iso))
System.out.println("this is GBK");
}catch(Exception e)
{
System.out.println(e);
}
}
public static String UnicodeToChinese(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"GBK");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
} public static String ChineseToUnicode(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("GBK"),"ISO8859_1");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
}
如果,你是想得到本地系统的却省编码形式,直接到jvm的系统变量中取好了,dojsp(月下秋风)提供的那段程序真是在胡扯,而
http://expert.csdn.net/Expert/topic/989/989888.xml?temp=8.301944E-02
这段程序就更离谱了~