最近我到了深圳,在找工作,顺便复习一下基础,今天突然想到以前写过的代码,I/O方面的,代码如下:package com.sz.zgzstudy;import java.io.IOException;
import java.io.InputStream;public class test6 {
public static void main(String[] args) {
String pathName = "com/sz/zgzstudy/1.txt";
byte[] buff = new byte[1024];
int len = 0;
//从classpath路径里获取文件。
InputStream is = ClassLoader.getSystemResourceAsStream(pathName);
// 从文件读取数据
try {
while((len = is.read(buff)) != -1) {
System.out.write(buff, 0, len); //打印到控制台
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
}可是输出的是乱码,文件里面是中文信息各位大神,这是怎么回事,应该怎样设置字符集java字符集乱码问题
import java.io.InputStream;public class test6 {
public static void main(String[] args) {
String pathName = "com/sz/zgzstudy/1.txt";
byte[] buff = new byte[1024];
int len = 0;
//从classpath路径里获取文件。
InputStream is = ClassLoader.getSystemResourceAsStream(pathName);
// 从文件读取数据
try {
while((len = is.read(buff)) != -1) {
System.out.write(buff, 0, len); //打印到控制台
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
}可是输出的是乱码,文件里面是中文信息各位大神,这是怎么回事,应该怎样设置字符集java字符集乱码问题
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货