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 6349329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:35:40+00:00 2026-05-24T21:35:40+00:00

I am having this encoding issue in java, one string I actually need to

  • 0

I am having this encoding issue in java, one string I actually need to handle is the response from running “systeminfo” command under windows commandline, and I need to present the result in a html document. The problem is if I run my application on French operating system, the garbled characters are shown in the html, no matter how I tried to convert the encodeing settings.

From the log, I can see the system encoding is “Cp1252”, code snippet is as follows:

String systemEncoding = System.getProperty("sun.jnu.encoding");
log.info("sun.jnu.encoding="+systemEncoding);

In html builder class, I did something like this:

for(String line : lines){
    line = new String(line.getBytes("Cp1252"), "UTF8");
    osReport.append(line + "<br>");
}

Unfortunately, I still can see those garbled “question marks” all around, which are supposed to be some French characters..
The html header looks like this btw

<HEAD>
<META content="text/html; charset=UTF-8" http-equiv=Content-Type>
</HEAD>

How to get the response string, see the following piece of code please..

try{
    String systemEncoding = System.getProperty("sun.jnu.encoding");
    log.info("sun.jnu.encoding="+systemEncoding);
    InputStreamReader isr;
    if (StringUtil.isEmpty(systemEncoding)) {
        isr = new InputStreamReader(is);
    } else {
        isr = new InputStreamReader(is, systemEncoding);
    }
    BufferedReader br = new BufferedReader(isr);
    String line=null;
    while ((line = br.readLine()) != null) {
        res.append(line);
        res.append(LINE_SEP);
    }   
 } catch (IOException ioe) {
    log.error("IOException occurred while printing the response",ioe);
 }

Any help?? Thanks so very much!

  • 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-24T21:35:41+00:00Added an answer on May 24, 2026 at 9:35 pm

    I am assuming you are invoking the command via the Process type. I would expect systeminfo.exe to write output using the default ANSI encoding (windows-1252 on a French system.)

    That means that you can use the default encoding to read the input (the one used by the InputStreamReader(InputStream) constructor.) This will transcode the input from the default encoding to UTF-16. This code uses the Scanner type with the default system encoding:

    Process process = new ProcessBuilder(command).redirectErrorStream(true)
        .start();
    InputStream in = process.getInputStream();
    try {
      Scanner scanner = new Scanner(in);
      while (scanner.hasNextLine()) {
        lines.add(scanner.nextLine());
      }
      if (process.exitValue() != 0 || scanner.ioException() != null) {
        // throw exceptions
      }
    } finally {
      in.close();
    }
    

    Java strings are always UTF-16, so code like this is just a transcoding bug:

    new String(line.getBytes("Cp1252"), "UTF8");
    

    Ensure that you are encoding your HTML file correctly.

    Charset utf8 = Charset.forName("UTF-8");
    OutputStream out = new FileOutputStream(file);
    Closeable stream = out;
    try {
      Writer writer = new OutputStreamWriter(out, utf8);
      stream = writer;
      // write to writer here
    } finally {
      stream.close();
    }
    

    I would not try to read or directly change system properties like sun.jnu.encoding or file.encoding – these are JVM implementation details and their direct use or configuration is not supported.

    If you are relying on System.out to verify characters, ensure the device consuming the output decodes its input as windows-1252. See here for more on encoding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HTML string in ISO-8859-1 encoding. I need to pass this string
Having this line Cursor c = db.rawQuery(PRAGMA table_info(?), new String[] {tableName}); and getting this:
Having this XML view: <?xml version=1.0 encoding=utf-8?> <LinearLayout android:id=@+id/myScrollLayout android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical xmlns:android=http://schemas.android.com/apk/res/android> <ScrollView
I'm having a problem with encoding from a wordpress feed that I just can't
I'm having an issue running my application when certain elements exist in the layout
I'm currently having an issue with my xpath expressions in java. I'm trying to
I've been having this issue with initializing AudioRecord for Android. I searched for quite
I am having an issue selecting and displaying a substring from each of the
I'm having what I believe to be an encoding issue with a mysql connection
This code snippet isn't working, I'm getting an Authentication Failed. response from the server.

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.