The ConnectionTest 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));
ConnectionTest is one of those programs which
can make this simple change. Here is the new version of
ConnectionTest:
import java.net.*;
import java.io.*;
class ConnectionTest {
public static void main(String[] args) {
try {
URL yahoo = new URL("http://www.yahoo.com/");
URLConnection yahooConnection = yahoo.openConnection();
BufferedReader br = new BufferedReader(
new InputStreamReader(yahooConnection.getInputStream()));
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);
}
}
}