//****************************************************************************** 
// ----------------------------------------------------------- 
// tipsFile2.java (same tipsFile1.java in JDK 1.1 version) 
// ----------------------------------------------------------- 
// Comments : very simple text File applet JDK 1.11 version 
// ----------------------------------------------------------- 
// Author : R. BERTHOU 
// E-Mail : rbl@berthou.com 
// URL    : http://www.javaside.com 
// ----------------------------------------------------------- 
// 1.00 * R.BERTHOU  * 09/04/2000 * samples tips 
//****************************************************************************** 

 // Importations 
 import java.awt.* ; 
  
 import java.io.BufferedReader ; 
 import java.io.InputStreamReader ; 
 import java.net.URL ; 

 public class tipsFile2 extends java.applet.Applet { 
     // Variables 
      String s ; 
      TextArea t1 = new TextArea("") ; 

     // Initialisation de l'applet 
     public void init() {  
          setLayout(new GridLayout(1,1)) ;   // Define a Layout 
          add(t1) ;                               // add TextArea 

        readFile("tipsFile2.java") ;         // read a file (this source code) 
            
          t1.setText(s) ;                              // Put text in a TextArea 
     } 

     // readFile 
     public void readFile(String f) { 
          s = new String("") ; 

          // open stream to a file which name is expressed relative to the document URL 
          BufferedReader fis = null ; 

          // Open Stream 
         try { 
               URL u = new URL( getCodeBase(), f ) ; 
             fis = new BufferedReader( new InputStreamReader( u.openStream()) ) ; 
         } catch( Exception e ) { 
               s = "readFile : " + f + "\r\n --> Exception : " + e ; 
               return ; 
          } 

          String sS = new String("") ; 
           // read loop 
          while ( true ) { 
               try { 
                    sS = fis.readLine() ; 
                    if (sS != null) 
                         s = s + "\r\n" + sS ; 
                    else  
                         break ; // end of file 
               } catch( Exception e ) { 
                         break ; 
               }     
           } 
     } 
  } 

Generated by srcColor