首页 > 代码库 > java 流 读
java 流 读
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(); } }}
java 流 读
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。