Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading String continusouly using readUTF():DataInputStream

 
Anand Damodaran
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I can't able to read age?






Kindly help me...


with respect,
Anand

 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic