Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a Java Expert!

Join 244,296 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 875 people online right now. Registration is fast and FREE... Join Now!




is.readLine() deprecation error (Socket Programming)

 
Reply to this topicStart new topic

is.readLine() deprecation error (Socket Programming)

Israel
19 Oct, 2007 - 08:22 PM
Post #1

D.I.C Addict
Group Icon

Joined: 21 Nov, 2004
Posts: 649


Dream Kudos: 175
My Contributions
I was going through an old socket tutorial that I used a few months ago. I had no problem then. But when I tried it tonight I got an error that this part of the code had been deprecated:

CODE
"Client.java": [deprecation] readLine() in java.io.DataInputStream has been deprecated at line 42, column 43


That's great and all, but I'm having trouble finding what was now used to replace this. Anybody know? Here is the code in its entirety if anyone cares to know:

CODE
import java.io.*;
import java.net.*;
public class smtpClient {
    public static void main(String[] args) {
// declaration section:
// smtpClient: our client socket
// os: output stream
// is: input stream
        Socket smtpSocket = null;  
        DataOutputStream os = null;
        DataInputStream is = null;
// Initialization section:
// Try to open a socket on port 25
// Try to open input and output streams
        try {
            smtpSocket = new Socket("hostname", 25);
            os = new DataOutputStream(smtpSocket.getOutputStream());
            is = new DataInputStream(smtpSocket.getInputStream());
        } catch (UnknownHostException e) {
            System.err.println("Don't know about host: hostname");
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection to: hostname");
        }
// If everything has been initialized then we want to write some data
// to the socket we have opened a connection to on port 25
    if (smtpSocket != null && os != null && is != null) {
            try {
// The capital string before each colon has a special meaning to SMTP
// you may want to read the SMTP specification, RFC1822/3
        os.writeBytes("HELO\n");    
                os.writeBytes("MAIL From: k3is@fundy.csd.unbsj.ca\n");
                os.writeBytes("RCPT To: k3is@fundy.csd.unbsj.ca\n");
                os.writeBytes("DATA\n");
                os.writeBytes("From: k3is@fundy.csd.unbsj.ca\n");
                os.writeBytes("Subject: testing\n");
                os.writeBytes("Hi there\n"); // message body
                os.writeBytes("\n.\n");
        os.writeBytes("QUIT");
// keep on reading from/to the socket till we receive the "Ok" from SMTP,
// once we received that then we want to break.
                String responseLine;
                while ((responseLine = is.readLine()) != null) {
                    System.out.println("Server: " + responseLine);
                    if (responseLine.indexOf("Ok") != -1) {
                      break;
                    }
                }
// clean up:
// close the output stream
// close the input stream
// close the socket
        os.close();
                is.close();
                smtpSocket.close();  
            } catch (UnknownHostException e) {
                System.err.println("Trying to connect to unknown host: " + e);
            } catch (IOException e) {
                System.err.println("IOException:  " + e);
            }
        }
    }          
}




User is offlineProfile CardPM
+Quote Post


Martyr2
RE: Is.readLine() Deprecation Error (Socket Programming)
19 Oct, 2007 - 10:31 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 6,656



Thanked: 613 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
It is right on the documentation located at the URL below. It gives you what to replace it with and an example. Just lookup readline() to read all about it.

readline() Deprecated - using BufferReader instead

Enjoy! smile.gif

This post has been edited by Martyr2: 19 Oct, 2007 - 10:32 PM
User is offlineProfile CardPM
+Quote Post

Israel
RE: Is.readLine() Deprecation Error (Socket Programming)
21 Oct, 2007 - 04:57 PM
Post #3

D.I.C Addict
Group Icon

Joined: 21 Nov, 2004
Posts: 649


Dream Kudos: 175
My Contributions
So simple. I can't believe that I took a course on Java, with the compilier I'm using I'm using and they never pointed that out. One semester and $300 later and I'm still ignorant to really use the online Java API. I've always disliked Georgia Southern, I probably should have just enrolled at </dic>. Thanks!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 04:36PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month