Found reliance on default encoding in FileReader

Mike picture Mike · Aug 15, 2012 · Viewed 18k times · Source

How can we fix the below issue reported by findBugs:

Found reliance on default encoding in abc.java : new java.io.FileReader(File)

I'm just reading file & Findbug has reported the issue.

Any help is much appreciated!

Answer

jtahlborn picture jtahlborn · Aug 15, 2012

use an explicit character encoding when opening a file instead of relying on the platform default (which can change depending on the platform), unless of course, you intend to use the platform default. you can use InputStreamReader to convert a FileInputStream to a Reader using an explicit character encoding.