readLine() method

C

cold80

I'm starting to develop a Java application using sockets and IO
objects. I developed, for example, a sample Echo Server application
that read the input from a socket using a BufferedReader object and
write in the socket the same text using a BufferedWriter. But when I
read a string from BufferedReader using readLine() method, I receive a
string that starts with some strange characters. So I can't write this
string with a simple println(), and I don't know how I can do this. I
think these strange chars are some kind of format that java need to use
these objects, really I don't know...Could you help me please?

Many thanks

Sebastiano
 
S

Stefan Schulz

I'm starting to develop a Java application using sockets and IO
objects. I developed, for example, a sample Echo Server application
that read the input from a socket using a BufferedReader object and
write in the socket the same text using a BufferedWriter. But when I
read a string from BufferedReader using readLine() method, I receive a
string that starts with some strange characters. So I can't write this
string with a simple println(), and I don't know how I can do this. I
think these strange chars are some kind of format that java need to use
these objects, really I don't know...Could you help me please?

If you merely want to echo input data back across a socket, don't bother
using Reader objects, just use a char[] and Input / Output streams
 
J

John C. Bollinger

Stefan said:
If you merely want to echo input data back across a socket, don't bother
using Reader objects, just use a char[] and Input / Output streams
-----------------------------------^^^^^^

You misspelled "byte[]". Otherwise the advice is sound.
 
C

cold80

Ok, but I want to understand more about these IO objects. So I would
like to know why the return string of the method readLine() contains
these strange chars and how I can convert this string in a normal
string.

Thank you for you patience

Sebastiano
 
S

Stefan Schulz

Ok, but I want to understand more about these IO objects. So I would
like to know why the return string of the method readLine() contains
these strange chars and how I can convert this string in a normal
string.

Thank you for you patience

Hmm, most likely the readLine() method tries to encode input into
characters that is not meant to be encoded. "Random" binary data. And the
result will generally be less then well-readable.

Oh, and yes. I meant byte[]. I should know them by now (and hate them).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top