Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6985633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:42:19+00:00 2026-05-27T18:42:19+00:00

Console input (win), how is the charset convertion working? Code below, non-ascii chars output

  • 0

Console input (win), how is the charset convertion working?

Code below, non-ascii chars output garbage – InputStreamReader in the below example doesn’t take charset as an argument.

BufferedReader console = new BufferedReader( new InputStreamReader(System.in));
String inp = console.readLine();
System.out.println(inp.toUpperCase());

Being os-independent, how does Java solve all different possible charset configurations regarding console prompt input?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:42:20+00:00Added an answer on May 27, 2026 at 6:42 pm

    Actually, Java doesn’t handle this problem at all.

    It simply assumes that console encoding is the same as the system default encoding. This assumption is wrong on Windows systems, therefore Java doesn’t provide good solution to perform correct console IO with respect to non-ascii characters on Windows.

    Possible solutions are:

    • Use System.console() introduced in Java 6:

      BufferedReader in = new BufferedReader(System.console().reader());
      BufferedWriter out = new PrintWriter(System.console().writer(), true);
      
      out.println(in.readLine().toUpperCase());
      

      Note that System.console() can return null when you program run with redirected IO, for example, in IDE. You need a fallback for this case.

    • Specify console encoding explicitly:

      String consoleEncoding = "...";
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in, consoleEncoding));
      BufferedWriter out = new PrintWriter(new OutputStreamWriter(System.in, consoleEncoding), true);
      
      out.println(in.readLine().toUpperCase());
      

      As far as I know, there are no good ways to determine actual console encoding programmatically without native code.

    • Specify console encoding as default encoding using file.encoding property, so that the assumption that console IO uses default encoding would be correct:

      java -Dfile.encoding=... ...
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do you sink both the console input and the console output to a
How do I get an NSString from console input, and then try to cast
I'm trying to get console input in my Clojure program, but when it gives
If I want to get a user input from Console to my Expression Tree.
How can you set a default input value in a .net console app? Here
direct console to ok.log, and errors to error.log for example
In a .NET Win console application, I would like to access an App.config file
Using Java Generics, I tried to implement a generic console input method. public static
How to mask a password from console input? I'm using Java 6. I've tried
I want to write a simple program, that writes console input to file with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.