Well, you may be trying to read your file using a different encoding.
You need to use the OutputStreamReader
class as the reader parameter for your BufferedReader
. It does accept an encoding. Review Java Docs for it.
Somewhat like this:
BufeferedReader out = new BufferedReader(new OutputStreamReader(new FileInputStream("jedis.txt),"UTF-8")))
Or you can set the current system encoding with the system property file.encoding
to UTF-8.
java -Dfile.encoding=UTF-8 com.jediacademy.Runner arg1 arg2 ...
You may also set it as a system property at runtime with System.setProperty(...)
if you only need it for this specific file, but in a case like this I think I would prefer the OutputStreamWriter
.
By setting the system property you can use FileReader
and expect that it will use UTF-8 as the default encoding for your files. In this case for all the files that you read and write.
If you intend to detect decoding errors in your file you would be forced to use the OutputStreamReader
approach and use the constructor that receives an decoder.
Somewhat like
CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
decoder.onMalformedInput(CodingErrorAction.REPORT);
decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
BufeferedReader out = new BufferedReader(new InputStreamReader(new FileInputStream("jedis.txt),decoder));
You may choose between actions IGNORE | REPLACE | REPORT