Input in Java? - HOW?

Sharky Forums


Results 1 to 6 of 6

Thread: Input in Java? - HOW?

  1. #1
    Tiger Shark BobTheSlob's Avatar
    Join Date
    Sep 2000
    Location
    Atlanta, GA
    Posts
    667

    Post Input in Java? - HOW?

    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

    ------------------
    I LOVE ACRONYMS!!!AFK, DSL, LOL, ASP, HTML, ATA, SCSI, FSB, MWAHAHAHAHAHAHAHAHA
    "Ich bin ein Mann des internationalen Hauses der Pfannkuchen"

  2. #2
    Catfish
    Join Date
    Sep 2000
    Posts
    111

    Post

    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

    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 [email protected] 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).]
    - jeste®

    How could tomorrow ever follow today?

  3. #3
    Tiger Shark BobTheSlob's Avatar
    Join Date
    Sep 2000
    Location
    Atlanta, GA
    Posts
    667

    Post

    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

    ------------------
    I LOVE ACRONYMS!!!AFK, DSL, LOL, ASP, HTML, ATA, SCSI, FSB, MWAHAHAHAHAHAHAHAHA
    "Ich bin ein Mann des internationalen Hauses der Pfannkuchen"

  4. #4
    Catfish
    Join Date
    Sep 2000
    Posts
    111

    Post

    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

    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?
    - jeste®

    How could tomorrow ever follow today?

  5. #5
    Ex-*** kid A's Avatar
    Join Date
    Sep 2000
    Location
    Norway
    Posts
    5,322

    Post

    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
    Now listening to various rock and metal
    143rd member to join Sharkyforums.

  6. #6
    Catfish
    Join Date
    Sep 2000
    Posts
    111

    Post

    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?
    - jeste®

    How could tomorrow ever follow today?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •