TheOpenStreamTest
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));OpenStreamTest
is one of those programs which can make this simple change. Here is the new version ofOpenStreamTest
: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); } } }