//******************************************************************************
// -----------------------------------------------------------
// tipsRead.java (same tipsFile2.java in JDK 1.1 version)
// Read current html page
// -----------------------------------------------------------
// 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.io.IOException ;
public class tipsRead 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() ; // read a file
t1.setText(s) ; // Put text in a TextArea
}
// readFile
public void readFile() {
s = new String("") ;
// Define BufferedReader
BufferedReader fis = null ;
// Open Stream
try {
fis = new BufferedReader(
new InputStreamReader( getDocumentBase().openStream()) ) ;
} catch( IOException e ) {
s = "readFile 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( IOException e ) {
break ;
}
}
try {
fis.close() ;
} catch( IOException e ) { }
}
}
|