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
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: 1045
    
  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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading String continusouly using readUTF():DataInputStream