Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

deprecated method.... !!  RSS feed

 
Ashish Agnihotri
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Again a simple question... When I run the following code.. its says while compiling...
System.out.println (in.readLine());........ deprecated.
I checked Java API.. and true ! I need to instead use ...BufferedReader instead.
My question is .. if I use the syntax as below it still gives problem .. can anybody pl. help me ?
System.out.println (in.BufferedReader.readLine());
thanks.. the code is below..
Ashish

import java.io.*;
class FileInputDemo
{
public static void main(String args[])
{
// args.length is equivalent to argc in C
if (args.length == 1)
{
try
{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new
FileInputStream(args[0]);
// Convert our input stream to a
// DataInputStream
DataInputStream in =
new DataInputStream(fstream);
// Continue to read lines while
// there are still some left to read
while (in.available() !=0)
{
// Print file line to screen
------>//System.out.println (in.BufferedReader.readLine());
// above one is according to API documentation
------> System.out.println (in.readLine());
}
in.close();
}
catch (Exception e)
{
System.err.println("File input error");
}
}
else
System.out.println("Invalid parameters");
}
}
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct in your investigation. You need to completely replace the code that intanciates your input stream.
Replace
DataInputStream in = new DataInputStream(fstream);

With
BufferedReader in = new BufferedReader(new FileReader(fstream));
This is the perferred way (by Sun's documentation) to replace the deprecated method.
Hope this helps
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!