package com.lf.iopreoject; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; public class TestCode { public static void main(String[] args) { TestCode.testFileInputStream(); } public static void testFileInputStream() { //读取一个文件 File file = new File("song.txt"); BufferedReader br = null; try { String str; FileReader fr = new FileReader(file); br = new BufferedReader(fr); // 读取的结果不为空就在控制台打印 while ((str = br.readLine()) !=null) { System.out.println(str); } } catch (Exception e) { // TODO: handle exception }finally{ if (br!=null) { try { br.close(); } catch (Exception e) { // TODO: handle exception } } } } }