Reputation: 83
I want to enter value in console at run-time (during execution), rather than hard code it manually. I have following code:
System.out.println("Open the following URL and grant access to your account:");
System.out.println(requestToken.getAuthorizationURL());
String authURL=requestToken.getAuthorizationURL();
//Generate a pin number from auth url by login to twitter account.
String pinNum=GenratePIN_LoginTwitter.accessTokenForTwitter(authURL);
System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:");
String pin =br.readLine();
Here I want to insert the value of 'pinNum' in console and proceed with the next steps.Please suggest regarding it.
Upvotes: 1
Views: 3992
Reputation: 2614
Basically System.in is The standard input stream.this stream corresponds to keyboard input or another input source specified by the host environment or user. so you can use it in some of the java IO API.as @abhishek told for Scanner you can also use below code.
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
Upvotes: 0
Reputation: 878
If you want to get the input from the user from console use java.util.Scanner
class
System.out.println("Enter a number: ")
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
System.out.println("The number is: "+i);
The above code will help you to get the input from console
For more on Scanner
refer Oracle docs
Upvotes: 4