I have a couple of static methods, read from the console. In Maine, I launch both sequentially. Entered the data in one, closed the stream. The second method immediately falls out with an IOException .

Of course, you can put a BufferedReader in the class field and not close the stream, but I’m wondering if you can do without it.

    1 answer 1

    You can use the Console class to retrieve user data.

      Console cons; char[] passwd; if ((cons = System.console()) != null && (passwd = cons.readPassword("[%s]", "Password:")) != null) { ... java.util.Arrays.fill(passwd, ' '); } 

    System.console() always returns the same object. cons.reader() will return the Reader you and you can close it - this will not affect its operation.

    • Thanks for the help, already figured out. - Haart
    • @Haart If you are given an exhaustive answer, mark it as correct (checkmark the selected answer). - Mikhail Vaysman
    • Exactly, thanks. I did not pay attention that there is a tick. - Haart