java使用BufferedReader类读取文本文件

来源:互联网 发布:网络教育 同济大学 编辑:程序博客网 时间:2024/06/05 17:51
<pre class="java" style="box-sizing: border-box; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; font-size: 13px; white-space: pre-wrap; padding: 9.5px; margin-top: 0px; margin-bottom: 10px; line-height: 1.428571429; color: rgb(51, 51, 51); word-break: break-all; word-wrap: break-word; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px;">package com.yiibai.io; import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException; public class BufferedReaderExample { public static void main(String[] args) { BufferedReader br = null; try { String sCurrentLine; br = new BufferedReader(new FileReader("C:\\testing.txt")); while ((sCurrentLine = br.readLine()) != null) {System.out.println(sCurrentLine);} } catch (IOException e) {e.printStackTrace();} finally {try {if (br != null)br.close();} catch (IOException ex) {ex.printStackTrace();}} }}
package com.yiibai.io; import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException; public class BufferedReaderExample { public static void main(String[] args) { try (BufferedReader br = new BufferedReader(new FileReader("C:\\testing.txt"))){ String sCurrentLine; while ((sCurrentLine = br.readLine()) != null) {System.out.println(sCurrentLine);} } catch (IOException e) {e.printStackTrace();}  }}

                                             
0 0
原创粉丝点击