# Cannot read CJK text from file and convert to String correctly on Windows

**URL:** <https://forum.juce.com/t/cannot-read-cjk-text-from-file-and-convert-to-string-correctly-on-windows/20581>\
**Category:** Windows\
**Created:** [January 13, 2017, 8:00am UTC](https://forum.juce.com/t/cannot-read-cjk-text-from-file-and-convert-to-string-correctly-on-windows/20581 "2017-01-13T08:00:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sam/32/68_2.png) [@sam](https://forum.juce.com/u/sam)\
**Post date:** [January 13, 2017, 8:00am UTC](https://forum.juce.com/t/cannot-read-cjk-text-from-file-and-convert-to-string-correctly-on-windows/20581/1 "2017-01-13T08:00:25Z")

</div>

Hi,

I have a txt file containing Chinese text (see below link for that file). The encoding of the file, according to Notepad, is ANSI. Notepad can display it correctly.

Using **File::loadFileAsString** to read that file into String, Chinese text are incorrect.

> **[tz.txt](https://www.dropbox.com/s/9brjuhp56yfg8p2/tz.txt?dl=0)**
>
> Shared with Dropbox

Tracing down loadFileAsString, looks like String::createStringFromData always call getStringFromWindows1252Codepage, which calls CharacterFunctions::getUnicodeCharFromWindows1252Codepage to deal with the data from file.

Save the file as UTF-8 encoding then File::loadFileAsString works correctly. Using **MultiByteToWideChar** to convert loaded from file then convert it to String also work correctly.

- Windows 10 (System language set to Traditional Chinese)
- JUCE 4.3.0

I’ve down following but the result all the same:

1. Change JUCE\_STRING\_UTF\_TYPE to 8 or 16 or 32.
2. Change **Character Set** project setting in Visual Studio to Unicode

I will keep digging to see if there is better way to improve the CJK handling in JUCE. Any suggestion would be appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [January 17, 2017, 9:15am UTC](https://forum.juce.com/t/cannot-read-cjk-text-from-file-and-convert-to-string-correctly-on-windows/20581/2 "2017-01-17T09:15:05Z")

</div>

Hi sam,

The JUCE team is pretty busy at the moment, but we will get around to looking at this eventually.

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [January 24, 2017, 10:20am UTC](https://forum.juce.com/t/cannot-read-cjk-text-from-file-and-convert-to-string-correctly-on-windows/20581/3 "2017-01-24T10:20:57Z")

</div>

JUCE does **not** support loading text files with ANSI encoding. See the documentation for [`File::loadFileAsString`](https://www.juce.com/doc/classFile#a07b95f6831ee4ed5b49241ce6af8539d): the file must be in UTF-8 or UTF-16.

---

<div class="post-metadata">

**Author:** ![sam](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sam/32/68_2.png) [@sam](https://forum.juce.com/u/sam)\
**Post date:** [January 24, 2017, 12:34pm UTC](https://forum.juce.com/t/cannot-read-cjk-text-from-file-and-convert-to-string-correctly-on-windows/20581/4 "2017-01-24T12:34:03Z")

</div>

@fabian,

You are right, I missed that part. Thank you!
