Well, you can try reading your file using a different encoding.
You need to use the OutputStreamReader class as the read parameter for your BufferedReader . It accepts an encoding. Check out the Java Docs for this.
Somewhat:
BufeferedReader out = new BufferedReader(new OutputStreamReader(new FileInputStream("jedis.txt),"UTF-8")))
Or you can set the current system encoding with the file.encoding system property to UTF-8.
java -Dfile.encoding=UTF-8 com.jediacademy.Runner arg1 arg2 ...
You can also set it as a system property at runtime with System.setProperty(...) if it is needed only for that specific file, but in that case, I think I would prefer OutputStreamWriter .
By setting the system property, you can use FileReader and expect it to use UTF-8 as the default encoding for your files. In this case, for all files that you read and write.
If you intend to detect decoding errors in your file, you will have to use the OutputStreamReader approach and use the constructor that the decoder receives.
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 can choose between IGNORE | REPLACE | REPORT IGNORE | REPLACE | REPORT
source share