Skip to content

Instantly share code, notes, and snippets.

@lebe-dev
Created March 8, 2020 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lebe-dev/31e31a3399c7885e298ed86810504676 to your computer and use it in GitHub Desktop.
Save lebe-dev/31e31a3399c7885e298ed86810504676 to your computer and use it in GitHub Desktop.
// 1. Create text file with windows-1251 (or any other non-utf8 encoding) - source.txt
// 2. Execute that code
val sourceContent = File("source.txt").readText(Charset.forName("windows-1251"))
File("utf8.txt").writeText(String(sourceContent.toByteArray()))
// 3. Check utf8.txt file and you'll see text file with utf-8 encoding
For example sample text in russian windows-1251: а вот и текст
Source file in hex (source.txt):
E0 20 E2 EE F2 20 E8 20 F2 E5 EA F1 F2 0A
After this code execution:
D0 B0 20 D0 B2 D0 BE D1 82 20 D0 B8 20 D1 82 D0 B5 D0 BA D1 81 D1 82 0A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment