//PrintMe.java -- new PrintMe(Class); 就會把 Class.java 印出 //@CopyLeft by tsaiwn@csie.nctu.edu.tw import java.io.*; import java.util.*; import java.net.*; class PrintMe { String fn=""; static PrintStream cout = System.out; static BufferedReader br = null; public static Class theClass = null; PrintMe(Class who) { theClass = who; try{ fn = "" + who.getName( ) + ".java"; }catch(Exception e) {;} printOut( ); } void printOut( ) { System.out.println(fn); String fileName = fn; String s = null; getReader(fileName); if(br==null) return; int n = 0; try{ s = br.readLine( ); }catch(Exception e) {;} while(s != null) { // Java 要改為這樣偵測是否 EOF 檔案結束! //while( ! br.eof() ) { // 因 Java 的 BufferReader 沒有 eof( ) 可用 ++n; cout.printf("%5d %s\r\n", n, s); // for DOS/Windows try{s = br.readLine( );}catch(Exception e) {;} } // while cout.printf("\r\n"); // remove "\r" on Unix system }//printOut( public BufferedReader getReader(String fileName) { BufferedReader br = null; Class cc = theClass; try { InputStream is = cc.getResourceAsStream(fileName); br = new BufferedReader(new InputStreamReader( is ) ); }catch(Exception e) { System.err.println("? Can NOT find file: " + fileName); } return br; }// getReader( } //class PrintMe(