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