Method readLine() deprecated ?
I use this method a lot and it works too with JBuilder,
however I get warnings about it being deprecated.
Because of that I can't compile my application with
javac.
Do you know an alternative method ?
http://java.sun.com/products/jdk/1.2/docs/api/java/io/BufferedReader.html#readLine()
if i follow the link, i dont see readLine() to be deprecated,
Similar Messages
-
Hi there,
I have a DataInputStream object (code below). The code works great but I get a warning message below the code: dis.readLine()
The method readLine() from the type DataInputStream is deprecated
does anyone have an alternative to eliminate the warning?
DataInputStream dis = null;
String line = null;
//read
File f = new File(inputFolder+"/"+inputFileName);
FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
while ( (line=dis.readLine()) != null )
}http://java.sun.com/j2se/1.4.2/docs/api/java/io/DataInputStream.html
readLine()
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);
with:
BufferedReader d
= new BufferedReader(new InputStreamReader(in)); -
Error: The method ReadLine() is undefined for the typ of Objectkey.
I'm new at Java. Can anyone help??? Much appreciated.
public class readfilesAppd {
// /define string newline for line.seperator
private static final String nl = System.getProperty("line.separator");
private static final String userpath = System.getProperty("C:/Documents and Settings/GheeL/My Documents/My Data/835 ERA files/");
// public static void main(String[] args, Object fr) {
public static void main(String [] args) {
try {
ObjectKey br = null;
//struct stat request_stat_path(char C:/Documents and Settings/GheeL/My Documents/My Data/835 ERA files/, Request *rq);
// Create file
//FileReader fr = new FileReader("C:/Documents and Settings/GheeL/My Documents/My Data/835 ERA files/");
//String FILENAME = "";
String FILENAME = userpath;
String record = new String();
int recCount = 0;
while ((record = br.ObjectKey())) != null)
recCount++;
FILENAME = record.substring(780, 792);
FileWriter fstream = new FileWriter("ERA Loads.txt", true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(FILENAME+" "+recCount);
out.close();
System.out.println(FILENAME);
System.out.println(recCount);
catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
finally {
System.out.println("Is that something to cheer about?");
}You haven't posted the correct code. The error is telling you that you're trying to call a method "ReadLine()" on an object that doesn't have a method by that name. The code you posted doesn't call anything called ReadLine(). Find the code where that happens and post it.
-
Method 'getAttributeInternal' deprecated
I'm creating a new page using Jdev 10.1.3 and getting warnings as
Method 'getAttributeInternal' deprecated
How to fix this?
Thanks!Dont worry abt these Warnings. Anyway they are being generated by OA Framework and not you.
Sometimes you might need to replace these by populateAttribute, but till the time there is no issue I recommend against doing any modification to autogenerated code.
Regards
Sumit -
How to Diasble JLabel since enable(false) method is deprecated in jdk1.4
Hi friends
i am using jdk1.4 in which enable method is deprecated.
i am disabling my jlabel using jlabel.enable(false); method
however this is deprecated.
what method should i then use
please do helpYou just try with the .setEnabled(false); This will
help to solve your problem.Hey Thanks Mr. Sumode , its working with .setEnabled(false); -
How to mark a method as deprecated
Hello,
please does anyone knows how to mark a method as deprecated.
thanksI know about the documentation i mean about the method
itself.
is putting @deprecated at the documentation will
generate a warrning message if u did not use
-deprecation as a parameter while compilingThat is how to do it! You will only get a warning if you make use of a deprecated method. Why would you want to deprecate a method, and then carry on using it in your own code? You need to change the usages to whatever you have implemented to replace the missing required functionality. -
Blocking method 'readline()' in class BufferedReader??
I have this in some code:
BufferedReader in = new BufferedReader(
new InputStreamReader(
socket.getInputStream()));
String inputLine, outputLine;
while ((inputLine = in.readLine()) != null)
System.out.println("TEST");
outputLine = inputLine + " TXT ADDED";
out.println(outputLine);
}The while loop only get executed each time my client sends a message. Where in the API does it say that readline() blocks the thread until a new message is recevied?
I thought that either the while loop terminates or else it runs all the time printing "TEST". I am not used to this kind of 'continuing conditinal' execution of a while loop so I guess there is something I missing?Hey you're right. The BufferedReader API doesn't specifically mention blocking. However the Reader class (the superclass) mentions it. Actually I believe that all the input methods in java.io are blocking.
I'm not sure why you're not used to it. Blocking I/O is pretty common. In any event that's how it works. I believe that there is non-blocking I/O functionality provided in the java.nio package. -
I need a solution for the deprecated readLine() method .
import java.io.*;
import java.net.*;
class UC {
public static void main(String args[]) throws Exception
DataInputStream inFromUser = new DataInputStream(System.in);
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName("hostname");
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
while(true)
String[] sentence = inFromUser.readLine(); /* It says the readLine() method is deprecated. what is the solution for this? */
sentence.getSubstringBytes(sentence,0, sentence.length(), sendData, 0);
//sentence.getBytes(0, sentence.length(), sendData, 0);
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
clientSocket.send(sendPacket);
DatagramPacket receivePacket
= new DatagramPacket(receiveData, receiveData.length);
clientSocket.receive(receivePacket);
String modifiedSentence =
new String(receivePacket.getData());
System.out.println("FROM SERVER:" + modifiedSentence);
public void getSubstringBytes(String sentence,int space,int Size,byte[] sendData,int space)
byte[] bytes=sentence.getBytes();
System.arraycopy(bytes,0,sendData,0,sentence.length()-0);
}Sorry, It should be the BufferedReader , not BufferedInputStream.
-
My organization has recently come from the Microsoft world into the J2EE world. In .Net, Microsoft has an abort method on threads that is similar to the Java's stop method. Unfortunately, the stop method has been deprecated.
While I have read the information on why this method is dangerous, I don't understand why the method has been removed. If I have a situation that warrants killing a thread (such as in the case of an application server that hosts other threads of execution), why remove it from the platform? While I agree with Sun's article on seeking out alternative methods, there are still exceptions where a thread just needs to be interrupted so that it can get out of a deadlock, endless loop or blocking I/O.
Since the stop method is deprecated, is there an equivalent VM call that I can interface from native code?
I must say that I feel a bit like I'm being mothered by Sun.From your comments, you make a strong argument that suggests there's no need for a VM-level stop function.
This puzzles me because operating systems implement kill methods to terminate rogue processes, yet they remain efficient and manage to keep things clean. Granted, multiple processes don't generally share memory structures but certainly the OS, on their behalf, shares memory structures. I'm puzzled as to why similar desires/features aren't present in the JRE.
Regardless, short of running multiple JRE instances, each managing just one piece of work, the current deprecated status of the stop method renders Java without the ability to stop something that's gone wild unless the application is specifically pre-programmed to anticipate this behavior. (Of course that's a bit of a catch 22 in and of itself but...)
There is also a subscription to the notion that my company or company x can write perfect software that never hangs a Java-based application server. I feel that this is impractical -- especially when what businesses ask of IT continues to get more complex.
At this point perhaps it's fair to reveal the underlying reasons for my up-to-now, hypothetical questions. In my situation, company x is actually Sun. They failed to expose a socket timeout on their implementation of HTTPUrlConnection. I suppose that pretty much removes the luster from the argument that I, or anyone else, can write perfect software when the inventors of Java are themselves, imperfect. Of course, like you said and the JDK documents, the stop method will not abort a blocking socket read anyway (...although there's no reason why it couldn't except for more flawed design decisions...)
I've certainly investigated alternative packages but I'm just chasing a moving target. HTTPUrlConnection today, class x tomorrow. That's why I was wanting something at the framework level to provide a trap door so that recovery without terminating the JRE is possible. -
Date [deprecation] -- what other method?
Hi
I was using somethine like this in my code:
Date fecha2 = new Date(2009,4,24,20,30);And compiler, like java api 6, says that that method is deprecated.
I want to get an object of Date type, so i dont know what other method i can use to have the year, the month, the day, the hour and minutes in a Date type object.
I have been reading a bit about others, but i dont know how to use them to get a Date object.
Thanks and sorry for my language ;)CeciNEstPasUnProgrammeur wrote:
I have to admit that "getTime" is a rather stupid method name for returning a Date. Anyway, when reading the Javadocs, also pay attention to the section with inherited methods.Yeah... a bit stupid :P that was confused for me...
Ok, i told you what i have done, i think its good:
First of all:
private Calendar calendario=Calendar.getInstance(); Then insted of Date = new Date (int, int , int, int, int):
calendario.set(2008,4,24,20,30);
Date fecha = calendario.getTime();Its a bit longer, but well...
Thaks for your help. :) -
ILandscapeService method getSystem(systemAlias) is deprecated
Im using ILandscapeService method getSystem(systemAlias) to return information from my Sysytem Definition in the PCD, but this method is deprecated:
ILandscapeService landscapeService = (ILandscapeService) PortalRuntime.getRuntimeResources().getService(ILandscapeService.KEY);
ISystem system = landscapeService.getSystem(systemAlias);
Can anyone tell me the correct, or just a non-deprecated, way I should be obtaining the System Definition details, and the JAR files I need in the build path to use the service?
Cheers,
SteveHi Steve,
try the following code snippet.
//get initial context to lookup system object
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);
env.put(Context.SECURITY_PRINCIPAL, currentUser);
env.put(Constants.REQUESTED_ASPECT, PcmConstants.ASPECT_SEMANTICS);
InitialContext initialContext = null;
try{
initialContext = new InitialContext(env);
ISystems systemService = (ISystems)PortalRuntime.getRuntimeResources().getService(ISystems.KEY);
String systemId = systemService.getSystemId(alias);
ISystem system = (ISystem)initialContext.lookup(systemId);
catch(NamingException nException){
Best regards,
Martin -
Hello,
I need to declare deprecated a method into my classes and simply I don't know how. I've tried to use a javadoc comment @deprecated but after I compile I don't receive the message that this method is deprecated.
ThanxCheck "What happens when an API is Deprecated"
http://java.sun.com/products/jdk/1.1/docs/guide/misc/deprecation/deprecation.html
and read the note, that says if you compile the class with the deprecated method along with classes that uses this method, then you won't get a warning. :) -
PDFDocMerger API Deprecated mergePDFDocs Method
All,
We are trying to use the supplied PDFDocMerger API and running into some issues. When I look at the documentation it states that the mergePDFDocs method is deprecated; I do not see a replacement method. Is the documentation lacking updates and there is a new method to use or does the API simply not work anymore? I would really appreciate any insight into this issue as I need to merge PDFs and don't want to go outside the supplied API's.
Thanks in Advance,
JoshOk, just looked over the documentation one more time and realized process() replaces it.
Edited by: user11201963 on Aug 7, 2009 9:25 AM -
Need to generate html report on deprecated api
Hi All,
How do I write a generic tool that can print a report in html format of all the deprecated methods of a class and their count. Are there any freely downloadble tools that does this. What is the best way to do this if I have to write on my own.
Thanks & Regards,
Kumar.Yep:
1) Get hold of the source code for x-doclet tags and tinker around with them so that you can find all the deprecated tags in your system.
2) Write some code yourself that picks up all your files and searches for instance of the deprecated tag
3) Use javadoc to generate javadoc. Parse the output HTML using DOM/SAX parsers to find deprecated methods
Unfortunately, a class file never knows that a method is deprecated - so you cant use reflection to find deprecated methods (nor can you use BECL) -
Deprecated API compilation error
Please help. Attached is my source code. I'm receiving a compilation error that reads 'RnrBooksApp.java uses or overrides a deprecated API. Recompile with -deprecation for details.' I'm very new to Java, so I appreciate any assistance. Thank you!
//ClassName: RnrBooksApp
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
public class RnrBooksApp extends Frame implements ItemListener, ActionListener
//Declare database variables
Connection conBook;
Statement cmdBook;
ResultSet rsBook;
boolean blnSuccessfulOpen = false;
//Declare components
Choice lstBooks = new Choice();
TextField txtISBN = new TextField(13);
TextField txtTitle = new TextField(50);
TextField txtAuthor = new TextField(30);
TextField txtPublisher = new TextField(30);
Button btnAdd = new Button("Add");
//Button btnUpdate = new Button("Update");
Button btnEdit = new Button("Save");
Button btnCancel = new Button("Cancel");
Button btnDelete = new Button("Delete");
Label lblMessage = new Label(" ");
public static void main(String args[])
//Declare an instance of this application
RnrBooksApp thisApp = new RnrBooksApp();
thisApp.createInterface();
public void createInterface()
//Load the database and set up the frame
loadDatabase();
if (blnSuccessfulOpen)
//Set up frame
setTitle("Books Database");
addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent event)
stop();
System.exit(0);
setLayout(new BorderLayout());
//Set up top panel
Panel pnlTop = new Panel(new GridLayout(2, 2, 10, 10));
pnlTop.add(new Label("ISBN"));
lstBooks.insert("Select a Book to Display", 0);
lstBooks.addItemListener(this);
pnlTop.add(lstBooks);
pnlTop.add(new Label(" "));
add(pnlTop, "North");
//Set up center panel
Panel pnlMiddle = new Panel(new GridLayout(5, 2, 10, 10));
pnlMiddle.getInsets();
pnlMiddle.add(new Label("ISBN"));
pnlMiddle.add(txtISBN);
pnlMiddle.add(new Label("Title"));
pnlMiddle.add(txtTitle);
pnlMiddle.add(new Label("Author"));
pnlMiddle.add(txtAuthor);
pnlMiddle.add(new Label("Publisher"));
pnlMiddle.add(txtPublisher);
setTextToNotEditable();
Panel pnlLeftButtons = new Panel(new GridLayout(0, 2, 10, 10));
Panel pnlRightButtons = new Panel(new GridLayout(0, 2, 10, 10));
pnlLeftButtons.add(btnAdd);
btnAdd.addActionListener(this);
pnlLeftButtons.add(btnEdit);
btnEdit.addActionListener(this);
pnlRightButtons.add(btnDelete);
btnDelete.addActionListener(this);
pnlRightButtons.add(btnCancel);
btnCancel.addActionListener(this);
btnCancel.setEnabled(false);
pnlMiddle.add(pnlLeftButtons);
pnlMiddle.add(pnlRightButtons);
add(pnlMiddle, "Center");
//Set up bottom panel
add(lblMessage, "South");
lblMessage.setForeground(Color.red);
//Display the frame
setSize(400, 300);
setVisible(true);
else
stop(); //Close any open connection
System.exit(-1); //Exit with error status
public Insets insets()
//Set frame insets
return new Insets(40, 15, 15, 15);
public void loadDatabase()
try
//Load the Sun drivers
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch (ClassNotFoundException err)
try
//Load the Microsoft drivers
Class.forName("com.ms.jdbc.odbc.JdbcOdbcDriver");
catch (ClassNotFoundException error)
System.err.println("Drivers did not load properly");
try
//Connect to the database
conBook = DriverManager.getConnection("jdbc:odbc:Book");
//Create a ResultSet
cmdBook = conBook.createStatement();
rsBook = cmdBook.executeQuery(
"Select * from Book;");
loadBooks(rsBook);
blnSuccessfulOpen = true;
catch(SQLException error)
System.err.println("Error: " + error.toString());
public void loadBooks(ResultSet rsBook)
//Fill ISBN list box
try
while(rsBook.next())
lstBooks.add(rsBook.getString("ISBN"));
catch (SQLException error)
System.err.println("Error in Display Record." + "Error: " + error.toString());
public void itemStateChanged(ItemEvent event)
//Retrieve and display the selected record
String strISBN = lstBooks.getSelectedItem();
lblMessage.setText(""); //Delete instructions
try
rsBook = cmdBook.executeQuery(
"Select * from Book where [ISBN] = '"
+ strISBN + "';");
txtISBN.setText(strISBN);
displayRecord(rsBook);
setTextToEditable();
catch(SQLException error)
lblMessage.setText("Error in result set. " + "Error: " + error.toString());
public void displayRecord(ResultSet rsBook)
//Display the current record
try
if(rsBook.next())
txtTitle.setText(rsBook.getString("Title"));
txtAuthor.setText(rsBook.getString("Author"));
txtPublisher.setText(rsBook.getString("Publisher"));
lblMessage.setText("");
else
lblMessage.setText("Record not found");
clearTextFields();
catch (SQLException error)
lblMessage.setText("Error: " + error.toString());
public void actionPerformed(ActionEvent event)
//Test the command buttons
Object objSource = event.getSource();
if(objSource == btnAdd && event.getActionCommand () == "Add")
Add();
else if (objSource == btnAdd)
Save();
else if(objSource == btnEdit)
Edit();
else if(objSource == btnDelete)
Delete();
else if(objSource == btnCancel)
Cancel();
public void setTextToNotEditable()
//Lock the text fields
txtISBN.setEditable(false);
txtTitle.setEditable(false);
txtAuthor.setEditable(false);
txtPublisher.setEditable(false);
public void setTextToEditable()
//Unlock the text fields
txtISBN.setEditable(true);
txtTitle.setEditable(true);
txtAuthor.setEditable(true);
txtPublisher.setEditable(true);
public void clearTextFields()
//Clear the text fields
txtISBN.setText("");
txtTitle.setText("");
txtAuthor.setText("");
txtPublisher.setText("");
public void Add()
//Add a new record
lblMessage.setText(" "); //Clear previous message
setTextToEditable(); //Unlock the text fields
clearTextFields(); //Clear text field contents
txtISBN.requestFocus ();
//Set up the OK and Cancel buttons
btnAdd.setLabel("OK");
btnCancel.setEnabled(true);
//Disable the Delete and Edit buttons
btnDelete.setEnabled(false);
btnEdit.setEnabled(false);
public void Save()
//Save the new record
// Activated when the Add button has an "OK" label
if (txtISBN.getText().length ()== 0 || txtAuthor.getText().length() == 0)
lblMessage.setText("The ISBN or Author is blank");
else
try
cmdBook.executeUpdate("Insert Into Book "
+ "([ISBN], [Title], [Author], [Publisher]) "
+ "Values('"
+ txtISBN.getText() + "', '"
+ txtTitle.getText() + "', '"
+ txtAuthor.getText() + "', '"
+ txtPublisher.getText() + "')");
//Add to name list
lstBooks.add(txtISBN.getText());
//Reset buttons
Cancel();
catch(SQLException error)
lblMessage.setText("Error: " + error.toString());
public void Delete()
//Delete the current record
int intIndex = lstBooks.getSelectedIndex();
String strISBN = lstBooks.getSelectedItem();
if(intIndex == 0) //Make sure a record is selected
//Position 0 holds a text message
lblMessage.setText("Please select the record to be deleted");
else
//Delete the record from the database
try
cmdBook.executeUpdate(
"Delete from Book where [ISBN] = '" + strISBN + "';");
clearTextFields(); //Delete from screen
lstBooks.remove(intIndex); //Delete from list
lblMessage.setText("Record deleted"); //Display message
catch(SQLException error)
lblMessage.setText("Error during Delete."
+ "Error: " + error.toString());
public void Cancel()
//Enable the Delete and Edit buttons
btnDelete.setEnabled(true);
btnEdit.setEnabled(true);
//Disable the Cancel button
btnCancel.setEnabled(false);
//Change caption of button
btnAdd.setLabel("Add");
//Clear the text fields and status bar
clearTextFields();
lblMessage.setText("");
public void Edit()
//Save the modified record
int intIndex = lstBooks.getSelectedIndex();
if(intIndex == 0) //Make sure a record is selected
//Position 0 holds a text message
lblMessage.setText("Please select the record to change");
else
String strISBN = lstBooks.getSelectedItem();
try
cmdBook.executeUpdate("Update Book "
+ "Set [ISBN] = '" + txtISBN.getText() + "', "
+ "[Title] = '" + txtTitle.getText() + "', "
+ "[Author] = '" + txtAuthor.getText() + "', "
+ "[Publisher] = '" + txtPublisher.getText() + "' "
+ "Where [ISBN] = '" + strISBN + "';");
if (!strISBN.equals(txtISBN.getText()))
//Last name changed; change the list
lstBooks.remove(intIndex); //Remove the old entry
lstBooks.add(txtISBN.getText()); //Add the new entry
catch(SQLException error)
lblMessage.setText("Error during Edit. " + "Error: " + error.toString());
public void stop()
//Terminate the connection
try
if (conBook != null)
conBook.close();
catch(SQLException error)
lblMessage.setText("Unable to disconnect");How DO you compile then?
If you don't type "javac", you must be using an IDE.
In your IDE there should be some kind of configuration
tab or option for "compiler options" or compilation options
or compiler arguments... something like that.
put "-deprecation" in that text box and recompile.
Your compiler should tell you all about which methods
are deprecated -- you then go to your trust JavaDocs
and lookup those methods in the API and read WHY they
are deprecated (i.e. OLD, outdated, defunct, no longer used)
and what you should use instead. Then, correct your
code to no longer use the deprecated methods and instead
do things as suggested in the deprecation comments.
Maybe you are looking for
-
Capture One RAW Tiffs not previewing properly in Aperture
We just wrapped a big photoshoot and the photographer was using Capture One Pro. He gave me all of the raw files, but Capture creates RAW Tiffs. I imported them all to my Aperture, but now it's only showing me low-res jpeg previews. We switched compu
-
Installing existing app on a new laptop
I currently have Premier Pro CC installed on a desktop Mac. I will soon buy a new laptop, and will migrate applications from my desktop Mac to this new laptop. Do I need to pay an additional fee to run Premier Pro on the new laptop? I will only be us
-
I only have FTP access to a server that runs JSPs. Is there any way to get a database connection without physically going to the server?
-
Preset "GR Message" indicator depending on PO type?
Hi everyone, is there a possibility to preset the "GR Message" flag either depending on the PO type or depending on user parameters? I wasn't able to find a possibility. We need this just for a small group of users only using one specific PO type. An
-
Essbase RPD question - 2 columns
We build an Essbase BSO cube with historical data. Linked it to OBI (nothing special in the RPD done). Then we put a filter onto a column: FILTER("FinHist"."FinHist - measure" USING ("Years#1"."Years - Default" = '2006')) This works. BUT when we add