Solved

java. non-English characters encoding problem. intellij idea

Posted on 2016-10-09
3
82 Views
Last Modified: 2016-10-10
 
package com ; 
import java.io.UnsupportedEncodingException;

/**

 */
public class NewHW {
    public static void main(String[] args) throws UnsupportedEncodingException {
   System.out.println(   System.setProperty("file.encoding", "cp-1252")    );
    String s1 = "Përshëndetje botë!";

    byte[] bytes = s1.getBytes("utf-8");

    String s2 = new String(bytes, "cp1252");
    System.out.println(s2);
}
}

Open in new window


EXPECTED output: Përshëndetje botë!
Actual output: Përshëndetje botë!

Tried to get output in Albanian Hello World. However, the code above doesn't give me expected output. Please tell how should I change my code to meet my expectation.
I use windows 10.

Thanks in advance !
0
Comment
Question by:SunnyX
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 41835858
If what is in your editor actually looks like this (which is how it looks when i view this question page in a browser), then it's firstly a problem with the encoding used in your editor.

'Albanian'and you should fix that in your IDE's editor settings

This may be Albanian btw, but there is only one special character - "small letter e with diaresis". As such, that's not very exotic at all and most character encodings will deal with it perfectly well and so the following app should work in most cases:


public class Alb {
    public static void main(String[] args) {
        String s = "P\u00ebrshendetje Bot\u00eb";
        System.out.println(s);
    }
}

Open in new window

0
 

Author Closing Comment

by:SunnyX
ID: 41836688
thx
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 41836847
:)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 115
splitOdd10 challenge 5 104
How can I build my own IDE using ASP.NET MVC? 2 43
Android development question 2 34
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question