Results 1 to 7 of 7

Thread: how to read an input from the main method

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    how to read an input from the main method

    at the top of my class i have
    private static String SECRET_KEY = "";

    how do i read a key and set it to SECRET_KEY?

    if (SECRET_KEY == "") {
    System.out.println("Please enter a secre key which both the client and server will share:");
    }

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: how to read an input from the main method

    Through System.in. You might want to wrap an InputStreamReader and a BufferedReader around it to read a single line of input.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: how to read an input from the main method

    Quote Originally Posted by CornedBee
    Through System.in. You might want to wrap an InputStreamReader and a BufferedReader around it to read a single line of input.
    Thanks bud. any chance you can give me an e.g

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: how to read an input from the main method

    Code:
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
    String line = r.readLine().trim();
    Some stuff to import from java.io.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: how to read an input from the main method

    awesome thanks bud.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: how to read an input from the main method

    so i just simply do

    SECRET_KEY = line;

    ?

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: how to read an input from the main method

    Yeah, or you read directly into SECRET_KEY.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width