To read a file on the server, first instantiate a URL object:
|
try {
-
URL url = new URL( getCodeBase(), filename );
|
} catch ( MalformedURLException e ) {
-
System.err.println( "Bad URL:" + url.toString() );
|
}
|
where getCodeBase() returns the applet path. (Another method getDocumentBase() returns the path of the corresponding HTML document.)
|
Next, open a stream to this URL:
|
BufferedReader in =
-
new BufferedReader(
-
new InputStreamReader( url.openStream() ) );
|
The resulting character stream is treated like any other.
|