高分求助:8859_1 与 GBK 之间的转换 String text = ....;String convert = new String(text.getBytes("ISO-8859-1"), "GBK");就可以了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个很麻烦哦不过你给出了中文后稍微好一点举个例子"\311\317\264\253\316\304\274\376"读进来\311把311转为byte b得到byte[] ch然后new String(ch,"ISO8859_1")写出去的时候getByte("GBK"); 源代码如下:import java.io.UnsupportedEncodingException;public class Convert{ public static String toGBK(String source){ String GBKstr = ""; try{ GBKstr = new String(source.getBytes("iso-8859-1"),"GBK"); }catch(UnsupportedEncodingException e){ System.out.println("源字符串不是 iso-8859-1"); } return GBKstr; } public static void main(String[] args){ String str1 = "\311\317\264\253\316\304\274\376"; String str2 = "\315\250\320\305\263\314\320\362\325\375\303\246"; String str3 = "\262\273\304\334\275\370\320\320\311\317\264\253\265\304\267\376\316\361"; System.out.println("str1 = " + toGBK(str1)); System.out.println("str2 = " + toGBK(str2)); System.out.println("str3 = " + toGBK(str3)); }}运行结果是:str1 = 上传文件str2 = 通信程序正忙str3 = 不能进行上传的服务Press any key to continue... String str = new String(text.getBytes("ISO-8859-1"), "GBK");就行了 对,是有这个问题。我用FileInputStream从txt文件中读出byte[] buf来,再构建成String都不行。不知道怎么办了。 我一般这么用String str = new String(text.getBytes("ISO-8859-1"), "GBK"); 我也这么用String str = new String(text.getBytes("ISO-8859-1"), "GBK"); list转换成byte数组 正则问题 回文数问题? 客户端和服务器端的应用问题 请大家来帮我看看,这个页面的问题怎么解决啊? 一个继承关系的问题,100分求助,在线等=============== [求助]利用RandomAccessFile追加txt文件出现乱码 求助:怎样在主窗口之前显示登陆窗口??? Applet程序应该怎么样改成本地应用程序? 小弟想学java,有高手能指点我吗 关于关闭线程的问题 怎样得到明天的日期并转换成字符串?谢了
不过你给出了中文后稍微好一点举个例子
"\311\317\264\253\316\304\274\376"
读进来\311
把311转为byte b
得到byte[] ch
然后new String(ch,"ISO8859_1")写出去的时候getByte("GBK");
public static String toGBK(String source){
String GBKstr = "";
try{
GBKstr = new String(source.getBytes("iso-8859-1"),"GBK");
}catch(UnsupportedEncodingException e){
System.out.println("源字符串不是 iso-8859-1");
}
return GBKstr;
}
public static void main(String[] args){
String str1 = "\311\317\264\253\316\304\274\376";
String str2 = "\315\250\320\305\263\314\320\362\325\375\303\246";
String str3 = "\262\273\304\334\275\370\320\320\311\317\264\253\265\304\267\376\316\361";
System.out.println("str1 = " + toGBK(str1));
System.out.println("str2 = " + toGBK(str2));
System.out.println("str3 = " + toGBK(str3));
}
}运行结果是:
str1 = 上传文件
str2 = 通信程序正忙
str3 = 不能进行上传的服务
Press any key to continue...
我用FileInputStream从txt文件中读出byte[] buf来,再构建成String都不行。
不知道怎么办了。
String str = new String(text.getBytes("ISO-8859-1"), "GBK");
String str = new String(text.getBytes("ISO-8859-1"), "GBK");