关于读取文本中中文内容的问题 String text=new String(str.getBytes("8859_1"),"gb2312"); ~~~~~~~~iso-8859-1? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 显示汉字byte [] out; out = txt.getBytes("gb2312"); loveme_y(老猫),在从上一个页面接收text框里的数据的时候,直接用8859_1应该也可以的,所以应该不是这个问题的啦! guojun_2000_2000(阿刺),你的机器是什么环境?我的win32系统的环境是win2000+jdk1.3。linux的环境是redhat linux 7.0+jdk1.3。但是这应该不是什么问题呀! guojun_2000_2000(阿刺),你的是什么环境?为什么我的win2000+jdk1.3总是输出乱玛呢? 我也测试过你的代码,一字没改。输出中英文都正常。环境:win2k(简体中文版)+JDK1.3 关键要看你的文件和环境的编码……多试验几次,理解了:String text=new String(str.getBytes("8859_1"),"gb2312");这句的真正处理规则就知道了…… StringTokenizer tokenizer=new StringTokenizer(str,",");String text=tokenizer.nextToken();text=new String(text.getBytes("8859_1"),"GB2312"); ouxing(星星):这就奇怪了,为什么我的输出总是乱玛呢? 你那个list.txt文件是不是"8859_1"格式的啊。 老兄,注意JAVA使用Unicode,要转码才行public static String ConvertByte(byte[] bs) { try { ByteToCharConverter toChar = ByteToCharConverter.getConverter("Big5"); //GB2132 return new String(toChar.convertAll(bs)); } catch (Exception e) { System.out.println(e); return ""; } } sigama(聚集),能不能结合我的代码说明一下? 以流的方式读进文件,读进的数据就是byte[],然后转码就可以了.完整的代码等我写一个给你...... package test;import java.net.*;import java.io.*;import sun.io.ByteToCharConverter;import sun.io.ConversionBufferFullException;/** * Title: * Description: * Copyright: Copyright (c) 2001 * Company: * @author * @version 1.0 */public class ReadHZ { public static String ConvertByte(byte[] bs) { try { ByteToCharConverter toChar = ByteToCharConverter.getConverter("Big5"); //GB2132 return new String(toChar.convertAll(bs)); } catch (Exception e) { System.out.println(e); return ""; } } public static void main(String[] args) { String s; byte bt; byte[] bs = new byte[1024]; int i=1; try{ URL url = new URL("file:///e:/test.txt"); URLConnection uc = url.openConnection(); InputStream input = uc.getInputStream(); bs[0] = (byte)input.read(); while(true) { bt = (byte)input.read(); bs[i] = bt; if(bs[i]==bs[i-1]&&bs[i]==(byte)0xff) { byte[] bs2 = new byte[i-1]; for(int j=0;j<i-1;j++) bs2[j] = bs[j]; System.out.println(ReadHZ.ConvertByte(bs2)); break; } i++; } } catch(java.net.MalformedURLException e) { System.out .println(e.toString()); } catch(java.io.IOException e1) { System.out.println(e1.toString()); } }} sihama的代码不好用呀我怎么中文显示的是?呢? java-Class问题——高手指教 如何用程序自动拨号和断开,在XP下 HashMap<Key,Value>如何按照value(Not Key)值的大小排序? 在WEB服务器上发布含有applet的html时,遇见的问题,在线等 关于多线程的小问题~~~~~~ 乱码新问题,急问 我在家里设计的聊天室,调试都成功了,可是。。。。 help 如何使程序(字符界面)接受用户输入的一个浮点数,并把他的整数部分和小数部分分别输出。 关于Java..... 我想在JAVA中调用VC++的东西,怎么做?当然,这个系统只能在WINDOWS跑。 jbuilder ,javamail 问题
byte [] out;
out = txt.getBytes("gb2312");
我的win32系统的环境是win2000+jdk1.3。
linux的环境是redhat linux 7.0+jdk1.3。
但是这应该不是什么问题呀!
为什么我的win2000+jdk1.3总是输出乱玛呢?
环境:win2k(简体中文版)+JDK1.3
多试验几次,理解了:String text=new String(str.getBytes("8859_1"),"gb2312");这句的真正处理规则就知道了……
String text=tokenizer.nextToken();
text=new String(text.getBytes("8859_1"),"GB2312");
public static String ConvertByte(byte[] bs)
{
try
{
ByteToCharConverter toChar = ByteToCharConverter.getConverte
r("Big5"); //GB2132
return new String(toChar.convertAll(bs));
}
catch (Exception e)
{
System.out.println(e);
return "";
}
}
完整的代码等我写一个给你......
import java.io.*;
import sun.io.ByteToCharConverter;
import sun.io.ConversionBufferFullException;/**
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company:
* @author
* @version 1.0
*/public class ReadHZ {
public static String ConvertByte(byte[] bs)
{
try
{
ByteToCharConverter toChar = ByteToCharConverter.getConverter("Big5"); //GB2132
return new String(toChar.convertAll(bs));
}
catch (Exception e)
{
System.out.println(e);
return "";
}
} public static void main(String[] args) {
String s;
byte bt;
byte[] bs = new byte[1024];
int i=1; try{
URL url = new URL("file:///e:/test.txt");
URLConnection uc = url.openConnection();
InputStream input = uc.getInputStream();
bs[0] = (byte)input.read();
while(true)
{
bt = (byte)input.read();
bs[i] = bt;
if(bs[i]==bs[i-1]&&bs[i]==(byte)0xff)
{
byte[] bs2 = new byte[i-1];
for(int j=0;j<i-1;j++)
bs2[j] = bs[j];
System.out.println(ReadHZ.ConvertByte(bs2));
break;
}
i++;
} }
catch(java.net.MalformedURLException e)
{
System.out
.println(e.toString());
}
catch(java.io.IOException e1)
{
System.out.println(e1.toString());
} }
}
我怎么中文显示的是?呢?