Basic HTML version of Foils prepared Sept 21 1998

Foil 46 Read a File on the Server I

From Java Tutorial 98- 4: Multi-Treading, Useful Java Classes, I/O and Networking NAVO Tutorial -- Sept 23 1998. by Geoffrey C. Fox, Nancy McCracken

Reading a file by URL for Foil 46
1 To read a file on the server, first instantiate a URL object:
2 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() ) );
3 The resulting character stream is treated like any other.

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Nov 28 1998