标签:style blog color io ar java sp div c
package 流; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; public class 读 { public static void main(String[] args) { BufferedReaderDemo(); } public static void InputStreamDemo(){ try { InputStream inputStream=new FileInputStream("d://test.txt"); int ch=0; try { while((ch=inputStream.read())!=-1) { System.out.print((char)ch); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void FileReaderDemo(){ FileReader fileReader; try { fileReader = new FileReader("d://test.txt"); int ch=0; try { while((ch=fileReader.read())!=-1) { System.out.print((char)ch); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void BufferedReaderDemo(){ try { BufferedReader bufferedReader=new BufferedReader(new FileReader("d://test.txt")); String data; try { data = bufferedReader.readLine(); while(data!=null) { System.out.println(data); data=bufferedReader.readLine(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
标签:style blog color io ar java sp div c
原文地址:http://www.cnblogs.com/huangcongcong/p/4003725.html