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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:38:41+00:00 2026-05-13T13:38:41+00:00

problem: I have a string containing special characters which i convert to bytes and

  • 0

problem: I have a string containing special characters which i convert to bytes and vice versa..the conversion works properly on windows but on linux the special character is not converted properly.the default charset on linux is UTF-8 as seen with Charset.defaultCharset.getdisplayName()

however if i run on linux with option -Dfile.encoding=ISO-8859-1 it works properly..

how to make it work using the UTF-8 default charset and not setting the -D option in unix environment.

edit: i use jdk1.6.13

edit:code snippet
works with cs = “ISO-8859-1″; or cs=”UTF-8”; on win but not in linux

        String x = "½";
        System.out.println(x);
        byte[] ba = x.getBytes(Charset.forName(cs));
        for (byte b : ba) {
            System.out.println(b);
        }
        String y = new String(ba, Charset.forName(cs));
        System.out.println(y);

~regards
daed

  • 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-13T13:38:42+00:00Added an answer on May 13, 2026 at 1:38 pm

    Your characters are probably being corrupted by the compilation process and you’re ending up with junk data in your class file.

    if i run on linux with option -Dfile.encoding=ISO-8859-1 it works properly..

    The "file.encoding" property is not required by the J2SE platform specification; it’s an internal detail of Sun’s implementations and should not be examined or modified by user code. It’s also intended to be read-only; it’s technically impossible to support the setting of this property to arbitrary values on the command line or at any other time during program execution.

    In short, don’t use -Dfile.encoding=…

        String x = "½";
    

    Since U+00bd (½) will be represented by different values in different encodings:

    windows-1252     BD
    UTF-8            C2 BD
    ISO-8859-1       BD
    

    …you need to tell your compiler what encoding your source file is encoded as:

    javac -encoding ISO-8859-1 Foo.java
    

    Now we get to this one:

        System.out.println(x);
    

    As a PrintStream, this will encode data to the system encoding prior to emitting the byte data. Like this:

     System.out.write(x.getBytes(Charset.defaultCharset()));
    

    That may or may not work as you expect on some platforms – the byte encoding must match the encoding the console is expecting for the characters to show up correctly.

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

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer // Allocate a new buffer (skip this if you already… May 16, 2026 at 9:53 am
  • Editorial Team
    Editorial Team added an answer I think // for truncation is reasonably well known, but… May 16, 2026 at 9:53 am
  • Editorial Team
    Editorial Team added an answer When a user visits a page, you want to log… May 16, 2026 at 9:53 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have problem with refering to special symbol in string: I have: path='C:\dir\dir1\dir2\filename.doc' and
I have this string containing a large chunk of html and am trying to
here is my problem I have the following array (for example) string[] arr =
i am building a search index that contains special names - containing ! and
I'm having a problem writing Norwegian characters into an XML file using C#. I
I have a JTable instance, containing a number of rows. The columns in this
I have problem with databinding in the Win.Forms DataGridView control. Example: public class A
I have a problem in searching solr using solrnet client.. problem is when query
I'm new with AutoMapper and have a problem I'm trying to solve. If I
I have used a UIWebView to simply show a string, with font size 14px

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.