Search code examples
javaeofconsole-input

What is the End Of File/Stream keyboard combination to use with System.in.read()


Apologize if this trivial question has already been answered, I cannot find it at SO. Reading lines from the IDE console with this Java trivial code (Windows 7 and Eclipse Kepler):

int v;
try { while ((v = System.in.read()) != -1) System.out.println(v); }
catch (IOException e) { ; }

How the user can make the value v equal to -1? (I've tried Ctrl + d-z-x-c-s-e and other keys without repeatable behavior, but the loop is interrupted randomly)


Solution

  • Control + D should send the EOF character as excepted , but it is an bug in Eclipse.

    One of the user reported as

        In Kepler 4.3 eclipse.buildId=4.3.0.M20130911-1000 on Linux the problem 
        still exists in the Java console. I found the following workaround:
    
        If you leave the console to focus on another view, and then refocus on the console,
        then Ctrl-D (EOF) works as expected.
    

    Follow here


    When using Eclipse in Windows, Control + Z sends the EOF character.