0

I have a UTF-8 file stored inside a java jar file. I am trying to read it using the method getResourceAsStream(), but the input stream reader that is returned by the function uses the default encoding, which is the ANSI one under Windows.

How can I read a UTF-8 text file from inside a jar?

4

2 回答 2

10

Create an InputStreamReader around the InputStream, specifying UTF-8 as the encoding.

Note: I'm not sure what you mean by "the input stream reader that is returned by the function uses the default encoding" - getResourceAsStream() returns an InputStream, which reads binary data. That's not a reader at all (dealing with character data).

于 2010-06-22T09:19:19.357 回答
0

native2ascii 可以帮助你。
它将非 ascii 字符转换为 utf-8 文件中的等效字符代码。
例如;
native2ascii -encoding Cp1254 input_file.txt output_file.properties
请享用...

于 2011-06-27T12:24:59.447 回答