你的位置:首页 > Java教程

[Java教程]IO流中将字节流转成字符流的方法


//字节流--->字符流
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(); }}