java 发现依赖于 FileReader 中的默认编码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11963462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Found reliance on default encoding in FileReader
提问by Mike
How can we fix the below issue reported by findBugs:
我们如何解决 findBugs 报告的以下问题:
Found reliance on default encoding in abc.java : new java.io.FileReader(File)
I'm just reading file & Findbug has reported the issue.
我只是在阅读文件,Findbug 已经报告了这个问题。
Any help is much appreciated!
任何帮助深表感谢!
采纳答案by jtahlborn
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.
打开文件时使用显式字符编码,而不是依赖平台默认值(可能会因平台而异),当然,除非您打算使用平台默认值。您可以使用显式字符编码InputStreamReader
将 a 转换FileInputStream
为 a Reader
。