import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; /** * @description 本类实现了按行读取文件内容到内存,并打印输出的操作 * @time 2010-3-2 */ public class readFile { public static void main(String []arg0) { try{ new readFile("d:/test.txt"); }catch (IOException e) { e.printStackTrace(); } } /** * @param file:文件的全路径名 * @throws IOException */ public readFile(String file) throws IOException { File f=new File(file); BufferedReader br=new BufferedReader(new FileReader(f)); String line=null; while ((line = br.readLine()) != null) { { System.out.println(line); } br.close(); } } }