Last active
March 4, 2025 22:24
-
-
Save skhatri/4466635 to your computer and use it in GitHub Desktop.
unmatched character between windows-1252 and utf-8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.encoding; | |
| import java.nio.charset.Charset; | |
| public class EncodingConversionTest { | |
| private String data = "\u201e \u20ac \u201a \u0192 \u2026 \u2020 \u2021 \u02c6 \u2030 \u0160 " | |
| + "\u2039 \u0152 \u017d" | |
| + "\u2018 \u2019 \u201c \u201d \u2022 \u2013 \u2014 \u02dc " | |
| + "\u2122 \u0161 \u203a \u0153 \u017e \u0178"; | |
| private void run() throws Exception { | |
| String unicodeToWindows = new String(data.getBytes("windows-1252"), | |
| "windows-1252"); | |
| System.out.println("unicode as windows-1252 " + unicodeToWindows); | |
| String windowsToUtf8 = new String(data.getBytes("windows-1252"), | |
| "utf-8"); | |
| System.out.println("windows to utf-8 " + windowsToUtf8); | |
| String unicodeToUtf8 = new String(data.getBytes("utf-8"), "utf-8"); | |
| System.out.println("unicode as utf-8 " + unicodeToUtf8); | |
| String utf8ToWindows = new String(data.getBytes("utf-8"), | |
| "windows-1252"); | |
| System.out.println("utf-8 to windows " + utf8ToWindows); | |
| String charset = Charset.defaultCharset().displayName(); | |
| System.out.println("default : " + charset); | |
| String unicodeToDefault = new String(data.getBytes(charset), charset); | |
| System.out.println("Default Charset " + unicodeToDefault); | |
| String utf8ToDefault = new String(data.getBytes("utf-8"), charset); | |
| System.out.println("Default Charset from UTF-8 " + utf8ToDefault); | |
| String windowsToDefault = new String(data.getBytes("windows-1252"), | |
| charset); | |
| System.out.println("Default Charset from Windows " + windowsToDefault); | |
| } | |
| public static void main(String[] args) throws Exception { | |
| EncodingConversionTest module = new EncodingConversionTest(); | |
| module.run(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment