• Post Reply Bookmark Topic Watch Topic
  • New Topic

about DataInputStream class  RSS feed

 
sharma sachin
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i want to develop simple program for the addition of two numbers by user input
please suggest me the procedure for using DataInputStream class,
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since it is for use with reading binary data, DataInputStream is not applicable in this context. you should probably use java.util.Scanner .
 
Naresh Shanmugam
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With Java 6 you have "Console" class, which has been made to meet the requirement as you have mentioned(to get input from user at runtime). You could use that.
 
Campbell Ritchie
Marshal
Posts: 56592
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may prefer to use java.lang.Scanner for keyboard input.

Beware: there is a pitfall with Console. A class executed from a .jar does not have a Console, and getting the Console object returns null.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Beware: there is a pitfall with Console. A class executed from a .jar does not have a Console, and getting the Console object returns null.


You mean, in that jar file, if we get a Console object, then it'll be a null object?
 
Campbell Ritchie
Marshal
Posts: 56592
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abimaran Kugathasan wrote:You mean, in that jar file, if we get a Console object, then it'll be a null object?
Look in the API documentation. Actually I meant a .jar opened with "javaw" which happens if you double-click the .jar's icon.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!