Solved

java. non-English characters encoding problem. intellij idea

Posted on 2016-10-09
3
73 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

919 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now