[Java] 字符流Reader,读取字符数据
package test.stream; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; /** * 字符流 Reader * @author Frost.Yen * @E-mail 871979853@qq.com * @date 2016年4月13日 */ public class TestReader { public static void main(String[] args) { BufferedReader br = null; try { //字符流用来读取字符数据,对于输入字符流而言,最为常用的操作方法是使用BufferedReader,因为该流有个readLine() br = new BufferedReader(new FileReader("E:\\JAVA\\Examples\\To Learn\\src\\test\\stream\\test.txt")); String str = null; while((str = br.readLine())!=null){ System.out.println(str); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { if(br!=null) br.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
------------------------------------------------------------------
Always put yourself in the other's shoes.If you feel that it hurts you,it probably hurts others,too.------------------------------------------------------------------
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步