package ioTest; import java.io.*; /** * 18.编写一个Java应用程序,该程序使用FileInputStream类, * 实现从磁盘读取本应用程序源代码文件,并将文件内容显示在屏幕上。(本题20分) * * @since 2010-9-26 * @start 8:50 * @end 9:00 * */ public class Eighteen_SelfReader { public static void main(String args[]){ File file=new File("src/ioTest/Eighteen_SelfReader.java"); System.out.println(file.getAbsolutePath()); FilePrinter.printFileContent(file); } } class FilePrinter{ public static void printFileContent(File file){ try{ FileInputStream fis=new FileInputStream(file); InputStreamReader isr=new InputStreamReader(fis); BufferedReader br=new BufferedReader(isr); String str=br.readLine(); while(str!=null){ System.out.println(str); System.out.println("/r"); str=br.readLine(); } fis.close(); isr.close(); br.close(); fis=null; isr=null; br=null; } catch(Exception e){ } } }