wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Reading String continusouly using readUTF():DataInputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Reading String continusouly using readUTF():DataInputStream" Watch "Reading String continusouly using readUTF():DataInputStream" New topic
Author

Reading String continusouly using readUTF():DataInputStream

Anand Damodaran
Greenhorn

Joined: Oct 04, 2012
Posts: 21
Hi Friends,

I can't able to read age?






Kindly help me...


with respect,
Anand

Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1035
    
  10

DataInputStream.readUTF() assumes that the bytes of the wrapped input have (in outline) a format consisting of the length of the string followed by the UTF-8 bytes. You cannot supply these from the command line using System.in. Similarly, DataInputStream.readInt() requires that the wrapped input be exactly 4 bytes in big endian twos compliment format which you can't type to System.in.

It seems to me that you should be reading the input using java.util.Scanner .

Anand Damodaran
Greenhorn

Joined: Oct 04, 2012
Posts: 21
Richard Tookey wrote:DataInputStream.readUTF() assumes that the bytes of the wrapped input have (in outline) a format consisting of the length of the string followed by the UTF-8 bytes. You cannot supply these from the command line using System.in. Similarly, DataInputStream.readInt() requires that the wrapped input be exactly 4 bytes in big endian twos compliment format which you can't type to System.in.

It seems to me that you should be reading the input using java.util.Scanner .



Thank you very much for your reply.

Since i'm a beginner i can't understand the encoding formats.

But i concluded that we can't read input from console successfully using DataInputStream.


Thanks and Regards,
Anand
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Reading String continusouly using readUTF():DataInputStream
 
Similar Threads
What does this code mean?
How to Change the File Name for Each Uploaded Files to the Socket Server?
Help me Socket
Transfer multiple files from Server to Client using Sockets
sending an integer to a client machine