View Full Version : Java: Deprecated DataInputStream problem

December 12th, 2008, 12:35 AM
I have a problem with the DataInputStream throwing a deprecated warning when I compile. The file does actually compile and run, but it gives the following output after compiling:

Note: Duplicate.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

FileInputStream fileInputStream = null;

BufferedInputStream bufferedInputStream = null;

DataInputStream dataInputStream = null;

// Make file IO available

fileInputStream = new FileInputStream(file);

bufferedInputStream = new BufferedInputStream(fileInputStream);

dataInputStream = new DataInputStream(bufferedInputStream);

// While the line is not empty process the line
while (dataInputStream.available() != 0)

String string = null;

string = dataInputStream.readLine();

number = Integer.parseInt(string);

Does anyone know how I can substitute the buffered reader here without breaking the code??

December 12th, 2008, 01:00 AM
This is explained in the javadocs


Deprecated. This method does not properly convert bytes to characters. As of JDK 1.1, the preferred way to read lines of text is via the BufferedReader.readLine() method. Programs that use the DataInputStream class to read lines can be converted to use the BufferedReader class by replacing code of the form:

DataInputStream d = new DataInputStream(in);


BufferedReader d
= new BufferedReader(new InputStreamReader(in));

Use a BufferedReader (readLine method)