简体   繁体   中英

Not able to Build .ear file to have Text file encoding=UTF-8

I have some code deals with Chinese characters. In my eclipse I set project -> Properties -> Resource -> Text file encoding = UTF-8 . And I use javac.encoding=UTF-8 to build my .ear through ANT. When run my .ear in Websphere7. But somehow the Text file is not encoded as UTF-8 anymore.

The problem is in UTF-8, String.getBytes( ).length will return 3 for each Chinese character, but without UTF-8, all Chinese characters become "?", so String.getBytes() .length returns 1 for each character. I need to find a way to make it to return 3.

What am I missing? Is there a setting in Websphere I need to set?

Thanks,

How are you reading the file? Did you read with UTF-8 charset?

InputStream stream = Thread.currentThread()
        .getContextClassLoader().getResourceAsStream("com/app/myfile.txt");
InputStreamReader streamReader = new InputStreamReader(stream, "UTF-8");
BufferedReader reader = new BufferedReader(streamReader);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM