JDK-8295672 : Provide a better alternative to reading System.in
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Priority: P4
  • Status: Closed
  • Resolution: Withdrawn
  • OS: generic
  • CPU: generic
  • Submitted: 2022-10-19
  • Updated: 2025-04-07
  • Resolved: 2025-03-25
Related Reports
Relates :  
Description
Reading `System.in` is problematic as it is an input stream encoded in the host's encoding. With the JEP 400, there are cases where the default encoding (UTF-8) and host's native encoding differ. To read the bytes correctly, users would have to convert the bytes native-to-default, which seems to be an obstacle for basic usage. Providing a better means to access (w/o considering encoding stuff) would be appropriate. One option is to let users to use System.console(), but it won't work if the JVM is not attached to a console.

Some possible options include:
- Scanner.consoleScanner(): Returns Console.reader()
- Reader.consoleReader(): Returns Console.reader()
- System.inReader(): Returns Console.reader() if exists, otherwise a BufferedReader on System.in
Comments
java.io.IO (java.lang.IO in future) does this.
25-03-2025