开发者

How can I read a UTF-8 text file from a jar using the Java method Class.getResourceAsStream()?

开发者 https://www.devze.com 2023-01-04 12:59 出处:网络
I have a UTF-8 file stored inside a java jar file. I am trying to read it using the method getResourceAsStream(), b开发者_JAVA百科ut the input stream reader that is returned by the function uses the d

I have a UTF-8 file stored inside a java jar file. I am trying to read it using the method getResourceAsStream(), b开发者_JAVA百科ut 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?


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).


native2ascii may help you.
it converts non-ascii characters to equivalent character codes inside your utf-8 file.
for example;
native2ascii -encoding Cp1254 input_file.txt output_file.properties
enjoy...

0

精彩评论

暂无评论...
验证码 换一张
取 消