HELP! * GREY=local LOCAL HTML version of Foils prepared July 10 1996

Foil 184 Accessing URL's in Java -- InputStreams and URLConnections

From Basic Lectures on Java Language Applets Graphics Networking Trip to China and Icase Tutorial -- July 12-28 and June 10-13 96. by Geoffrey C. Fox * See also color IMAGE

String line; // Here is a useful example
try { URLConnection conn = npacurl.openConnection();
conn.connect(); // could set options after creation of conn in above line and before connect method invoked
InputStream in = conn.getInputStream(); // establish an InputStream on this connection
DataInputStream data = new DataInputStream(new BufferedInputSream(in)); // set up two filters allowing both buffering and line access to InputStream
while ((line = data.readline()) != null ) {
  • System.out.println("line"); } // print out line -- obviously put your favorite line processing here
} catch (IOException e) {processerror}
Note one useful exception EOFException which can be caught and remove testing in read loops



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 Tue Feb 18 1997