Take the 2-minute tour ×

I'm trying to read a line from console in java. Here is my code:

System.console().readLine("shell $ ");

This works, but I want to use beloved linux features like arrows to move cursor (not inserting ^[[C like now), up arrow should address previous command, tab should autocomplete something (this is not nesessary, but useful, i will be satisfied with correct arrows behaviour).

And -- no, I want to use "pure java" solution, not JNI wrapper for libreadline.

Is there some functionality in JDK itself or some frameworks which provide such functions?

share|improve this question
It might be overkill, but JCurses can do a lot of this (and more really) –  Jason Sperske Feb 27 '13 at 17:35
Also something called the Enigma Console library –  Jason Sperske Feb 27 '13 at 17:36
add comment

3 Answers

There is no such in-built functionality in java. For being able to do so i.e. creating a console able to do things like cycling through previous commands, moving around with arrow key, there is a need to write a action handler for such keys which is not possible in java (as per the in built functionality) because the input is buffered in java and it get's flushed as soon as you press Enter.

You might be able to do so in JNI i.e. Java Native Language. As far as I know, you can look at java console api, more details on this blog.

share|improve this answer
add comment
up vote 1 down vote accepted

I have to respond myself.

I didn't found really pure java library to handle it, but it can be written for *nix with no doubt (System.in is NOT buffered in fact).

I'm using jline2 (https://github.com/jline/jline2) https://github.com/jline/jline2now because it small enogh and requires binary additions only to support windows; I've tested it's jars and they're working without recompilation on any *nix and win32 OS I've ever found.

So, answer is: This is possible, but noone have written such 100% pure library.

share|improve this answer
add comment

Sunilkumkar from vmoksha

   public class ReadConsoleSystem {
    public static void main(String[] a``rgs) { 
System.out.println("Enter something here : "); 
    BufferedReader bufferRead = new 
     BufferedReader(new      InputStreamReader(System.in));
    String s = bufferRead.readLine(); 
catch(IOException e)

share|improve this answer
add comment

Your Answer


