01 //PrintMe.java -- new PrintMe(Class); 就會把 Class.java 印出
   02 //@CopyLeft by tsaiwn@csie.nctu.edu.tw
   03 import java.io.*;
   04 import java.util.*;
   05 import java.net.*;
   06 import java.awt.*;
   07 import java.applet.*;
   08 class PrintMe  extends Applet {
   09     String fn="";
   10     static PrintStream cout = System.out;
   11     static BufferedReader br = null;
   12     public static Class theClass = null;
   13     PrintMe(Class who) {
   14        theClass = who;
   15        try{
   16           fn = "" + who.getName( ) + ".java";
   17        }catch(Exception e) {;}
   18        printOut( );
   19     }
   20     void printOut( ) {
   21         System.out.println(fn);
   22         String fileName = fn;
   23         String s = null;
   24         br = getReader(fileName);  if(br==null) return;
   25         int n = 0;
   26         try{
   27            s = br.readLine( );
   28         }catch(Exception e) {;}
   29         while(s != null) {     // Java 要改為這樣偵測是否 EOF 檔案結束!
   30         //while( ! br.eof() ) {   // 因 Java 的 BufferReader 沒有 eof( ) 可用
   31              ++n;
   32              cout.printf("%5d %s\r\n", n, s);   // for DOS/Windows
   33              try{s = br.readLine( );}catch(Exception e) {;}
   34          } // while
   35          cout.printf("\r\n");   // remove "\r" on Unix system
   36     }//printOut(
   37     public BufferedReader getReader(String fileName) {
   38          BufferedReader br = null;
   39          InputStream is  = null;
   40          Class cc = theClass;
   41          try {
   42              is = cc.getResourceAsStream(fileName);
   43              br = new BufferedReader(  new InputStreamReader(is) );
   44          }catch(Exception e) {
   45              System.err.println("? Can NOT find file: " + fileName);
   46          }
   47          return br;
   48     }// getReader(
   49 } //class PrintMe(