TheConnectionTest
example uses theDataInputStream.readLine
method which has been deprecated in the JDK 1.1 because it does not convert correctly between bytes and characters. Most programs that useDataInputStream.readLine
can make a simple change to use the same method from the newBufferedReader
class instead. Simply replace code of the form:with:DataInputStream d = new DataInputStream(in);BufferedReader d = new BufferedReader(new InputStreamReader(in));ConnectionTest
is one of those programs which can make this simple change. Here is the new version ofConnectionTest
: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); } } }