IO流中将字节流转成字符流的方法

来源:互联网 发布:淘宝客内部优惠券软件 编辑:程序博客网 时间:2024/05/22 13:35

http://blog.sina.com.cn/s/blog_8da6f909010135l1.html

/字节流--->字符流
1.public class TestIO {
 public static void main(String[] args) throws IOException {
  FileInputStream fis = new FileInputStream("c:/abc.txt");// 字节流
  InputStreamReader isr = new InputStreamReader(fis);// 字符流
  BufferedReader br = new BufferedReader(isr);// 缓冲流
  String str = null;
  if ((str = br.readLine()) != null) {
   System.out.println(str);
  }
  br.close();
  isr.close();
  fis.close();
 }

}
2.public class TestIO {
public static void main(String[] args) throws IOException {
FileReader fr = new FileReader("c:/abc.txt");
  BufferedReader br = new BufferedReader(fr);// 缓冲流
  String str = null;
  if ((str = br.readLine()) != null) {
   System.out.println(str);
  }
  fr.close();
  br.close();

 

原创粉丝点击