import java.io.*;public class FileIn {
public static void main(String[] args) {
try {
FileInputStream rf = new FileInputStream(
"F:\\100个让心情变好的佛家领悟-佛家感悟.txt");
int b;
while ((b = rf.read()) != -1)
System.out.print((char) b);
rf.close();
} catch (IOException ie) {
System.out.println(ie);
} catch (Exception e) {
System.out.println(e);
}
}
}
public static void main(String[] args) {
try {
FileInputStream rf = new FileInputStream(
"F:\\100个让心情变好的佛家领悟-佛家感悟.txt");
int b;
while ((b = rf.read()) != -1)
System.out.print((char) b);
rf.close();
} catch (IOException ie) {
System.out.println(ie);
} catch (Exception e) {
System.out.println(e);
}
}
}
import java.io.*;public class FileIn {
public static void main(String[] args) {
try {
FileInputStream rf = new FileInputStream(
"F:\\100个让心情变好的佛家领悟-佛家感悟.txt");
BufferedReader br=new BufferedReader(new InputStreamReader(rf));
// int b;
// while ((b = rf.read()) != -1)
// System.out.print((char) b);
// rf.close();
String s="";
while((s=br.readLine())!=null){
System.out.println(s);
}
br.close();
} catch (IOException ie) {
System.out.println(ie);
} catch (Exception e) {
System.out.println(e);
}
}
}
public static void main(String[] args) {
try {
FileInputStream rf = new FileInputStream(
"F:\\100个让心情变好的佛家领悟-佛家感悟.txt");
BufferedReader br=new BufferedReader(new InputStreamReader(rf,"gbk"));
// int b;
// while ((b = rf.read()) != -1)
// System.out.print((char) b);
// rf.close();
String s="";
while((s=br.readLine())!=null){
System.out.println(s);
}
br.close();
} catch (IOException ie) {
System.out.println(ie);
} catch (Exception e) {
System.out.println(e);
}
}
}
while ((b = rf.read()) != -1)
System.out.print((char) b);
rf.close();
} 就算支撑中文,你这个能否打印出正确的字符呢?这个-1只是一个标志位而已,不是你理解的所谓数值,所以你这个用byte转换能得到什么?
UTF-8编码里,中文是3个字节,能否给个介绍类的文章?谢谢
Charset.forName("GBK").encode("中").array().length == 2
public class FileIn {
public static void main(String[] args) {
try {
FileReader fr = new FileReader(new BufferedReader(
"F:\\100个让心情变好的佛家领悟-佛家感悟.txt"));
String b;
while ((b = fr.readLine()) != null)
System.out.printb);
fr.close();
} catch (IOException ie) {
System.out.println(ie);
} catch (Exception e) {
System.out.println(e);
}
}
}
明确的说,不应该用字节流是 浅薄的说法,至少不确切FileReader只能用本地操作系统的编码,无法进行转码读取比如你本地gbk的系统,就无法读取utf8编码的文件这时候需要用InputStreamReader来做
大哥,你果然牛逼,还请以后多多指教啊