java中的IO流(2)----读取文本数据

来源:互联网 发布:人工智能分析用户行为 编辑:程序博客网 时间:2024/05/22 12:21
@Testpublic void fun2() {FileInputStream fis = null;InputStreamReader isd = null;try {//低端流绑定硬盘文件fis = new FileInputStream("c:/a.txt");//高端流(即字符流)绑定低端流isd = new InputStreamReader(fis);char[] buffer = new char[1024];//设置字符缓冲区while (true){int len = isd.read(buffer);if (len == -1){break;}String str = new String(buffer, 0, len);System.out.println(str);}} catch (Exception e) {// TODO: handle exception} finally {try {fis.close();} catch (Exception e) {throw new RuntimeException(e);}try{isd.close();}catch (Exception e) {throw new RuntimeException(e);}}}

0 0
原创粉丝点击