How to get the standard input in Java
Published: January 13, 2010 , Updated: January 7, 2010 , Author: mkyong
A quick example to show how to read the standard input in Java.
package com.mkyong.io; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class printStdIn{ public static void main (String args[]) { try{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String input; while((input=br.readLine())!=null){ System.out.println(input); } }catch(IOException io){ io.printStackTrace(); } } }
Any Java questions or problems? please post at this JavaNullPointer.com forum, see you there ~
Is it any better or worse to use ‘System.console().readLine()’?
I think I noticed when I used the System.console() in Windows that I got some builtin console-like features (like history of commands scrollable using arrows and such) but not for Mac?
[...] if directory is emptyGet the current working directoryConsole IOList of the Console IO examples.Get the standard inputJava I/O ReferenceJava I/O Documentation [...]