The OpenStreamTest example uses the
DataInputStream.readLine method which
has been deprecated in the JDK 1.1 because it does
not convert correctly between bytes and characters.
Most programs that use DataInputStream.readLine
can make a simple change to use the same method from the
new BufferedReader class instead.
Simply replace code of the form:
DataInputStream d = new DataInputStream(in);
with:
BufferedReader d = new BufferedReader(new InputStreamReader(in));
OpenStreamTest is one of those programs which
can make this simple change. Here is the new version of
OpenStreamTest:
import java.net.*;
import java.io.*;
class OpenStreamTest {
public static void main(String[] args) {
try {
URL yahoo = new URL("http://www.yahoo.com/");
BufferedReader br = new BufferedReader(
new InputStreamReader(yahoo.openStream()));
String inputLine;
while ((inputLine = br.readLine()) != null) {
System.out.println(inputLine);
}
br.close();
} catch (MalformedURLException me) {
System.out.println("MalformedURLException: " + me);
} catch (IOException ioe) {
System.out.println("IOException: " + ioe);
}
}
}