Click to See Complete Forum and Search --> : Input in Java? - HOW?
BobTheSlob
01-08-2001, 07:59 PM
Heres the deal -
I have looked through my 1100 page Java book, downloaded a very large Java book, and looked around the internet, and I cant find anything that even resembles "cin" in Java. Does it exist? Or are you only supposed to have input via some kind of window?
It's very hard going through a Java book without some kind of program you want to make as your goal, and, you can't make much of a program without user input http://www.sharkyforums.com/ubb/wink.gif
------------------
I LOVE ACRONYMS!!!AFK, DSL, LOL, ASP, HTML, ATA, SCSI, FSB, MWAHAHAHAHAHAHAHAHA
jester
01-09-2001, 12:40 AM
Originally posted by BobTheSlob:
Heres the deal -
I have looked through my 1100 page Java book, downloaded a very large Java book, and looked around the internet, and I cant find anything that even resembles "cin" in Java. Does it exist? Or are you only supposed to have input via some kind of window?
It's very hard going through a Java book without some kind of program you want to make as your goal, and, you can't make much of a program without user input http://www.sharkyforums.com/ubb/wink.gif
Your in for a wild one. There is no cin type of method in java. Every I/O operation is done with the java.io package. There is a class for byte I/O and character I/O. The byte I/O classes use the java.io.InputStream and java.io.OutputStream classes. The character I/O classes use the java.io.Reader and java.io.Writer classes. Its a rather complex process when your using these classes for the first time. When using the derived classes, from the ones above, its good to put them in a buffer.
If you'd like I have this GUI program that you can have, i'll have to email it to you though. Its about 10 files long. I've placed all my classes in seperate files. I always learn more from example source than anything. Email me at bkukwa@telocity.com if you'd like to have it.
------------------
- jeste®
How could tomorrow ever follow today?
[This message has been edited by jester (edited January 08, 2001).]
BobTheSlob
01-09-2001, 05:43 PM
Oyvay! (i KNOW that's spelled wrong)
It's apparent that Java is really NOT meant for any console programs! I might just hold off on the user input for a while, and wait till I get to the part in my book that talks about what you said. I knew there was input, but, I was hoping for more of a shortcut http://www.sharkyforums.com/ubb/wink.gif
------------------
I LOVE ACRONYMS!!!AFK, DSL, LOL, ASP, HTML, ATA, SCSI, FSB, MWAHAHAHAHAHAHAHAHA
jester
01-09-2001, 06:26 PM
Originally posted by BobTheSlob:
Oyvay! (i KNOW that's spelled wrong)
It's apparent that Java is really NOT meant for any console programs! I might just hold off on the user input for a while, and wait till I get to the part in my book that talks about what you said. I knew there was input, but, I was hoping for more of a shortcut http://www.sharkyforums.com/ubb/wink.gif
When my professor taught me I/O in Java, he basically spent the full 2 hours talking about it. So its definitly something you can't pickup in a few minutes. Once you get the hang of it though, its pretty easy. All of the I/O classes are used in the exact same manner. Atleast the ones that I have used. Some example source, your 1100 page java book, and an evening should do you fine.
------------------
- jeste®
How could tomorrow ever follow today?
kid A
01-10-2001, 08:21 AM
Are you talking about keyboard input here?
This may be partly what you are looking for:
BufferedReader stdin = new BufferedReader
(new InputStreamReader (System.in));
...
------------------
Now listening to:
Røyksopp - Apple
jester
01-10-2001, 01:43 PM
Originally posted by kid A:
Are you talking about keyboard input here?
This may be partly what you are looking for:
BufferedReader stdin = new BufferedReader
(new InputStreamReader (System.in));
...
Since you've put some of the code up here, I might as well finish it for ya...
String input;
try {
input = stdin.readLine();
} catch ( IOException ioe ) {
input = "< " + ioe.getMessage() + ">";
}
But remember, you have to have catch the exception. Otherwise the compiler throws an error. IOException would work or Exception would work. IOException is derived from Exception, so the whole polymorphism action is going on. I believe thats called polymorphism... if anyone knows, correct me if i'm wrong.
------------------
- jeste®
How could tomorrow ever follow today?