中文问题,紧急求救!有分!
shtbl.zip里有个文本文件***.***,文本文件里有些中文的数据,我想实现遇到换行和回车时要替换成',',现在我读取的时候这些中文显示不出来,哪位高手能解决他。
import java.io.*;
import java.util.jar.*;
import java.util.Enumeration;
import java.util.zip.*;
class getContentbyzip {
public static void main(String[] arg) throws Exception {
int count = 0;
int m = 0;
int n = 0;
try {
File e_file = new File("G:\\" + "shtbl.zip"); //源文件
ZipInputStream zipstream = new ZipInputStream(new FileInputStream(e_file));
//InputStreamReader isr=new InputStreamReader (zipstream);
//char[] c=new char[255];
//BufferedReader is = new BufferedReader(isr);
StringBuffer str = new StringBuffer();
String filename = new String(); //存放文件的名称
int len;
//因为zip中约定有且只有两个文件,故用此循环找出sbtbl.csv来
ZipEntry data = zipstream.getNextEntry();//
filename = (String) data.getName();
System.out.println(filename);//打印输出名称
int size = (int) data.getSize();
System.out.println("数据长度" + size);
len = 255;
byte[] b = new byte[len];
int read_len = -1;
int is_do=0;
StringBuffer sbf=new StringBuffer();
while ( (read_len = zipstream.read(b, 0, len) ) != -1) {
for (int k = 0; k <read_len; k++) {
if (13 == b[k]) {
b[k]=44;
count++;//统计数据行数
str.append(",");//遇到换行添加逗号]
} else if (10 == b[k]) {
b[k]=44;
str.append(",");
m++;//统计数据行数
} else {
n++;//字符数
str.append((char)b[k]);
is_do=0;
}
}
sbf.append(new String(b,"gb2312"));
}
System.out.println(sbf);//这里显示sbf,这样
System.out.println("行数:" + count);//打印行数
System.out.println("换行" + m);
System.out.println("转换前 "+str.toString());
System.out.println("转换后 "+new String((str.toString()).getBytes("ISO8859_1"),"gb2312"));
} catch (Exception ee) {
throw new Exception("从zip文件中取数据时出错!" + ee);
}