Solved

java. non-English characters encoding problem. intellij idea

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mapAB Challlenge 35 88
Modeling a class in java 5 32
Java and GPO 11 47
What is the Best Editor for PHP Development ? 5 30
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

757 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

23 Experts available now in Live!

Get 1:1 Help Now