findBugs 这个报的是什么异常

无止进 2013-01-11 05:13:33
InputStreamReader fileData = new InputStreamReader(file); 以前一直都是这样写,但这次用findBugs来检查报了异常,异常如下:

Bug: Found reliance on default encoding in trust.cpic.pub.pubfunc.ReadFile(String, int, int): new java.io.InputStreamReader(InputStream)

Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable. This will cause the application behaviour to vary between platforms. Use an alternative API and specify a charset name or Charset object explicitly.

Confidence: High, Rank: Of Concern (19)
Pattern: DM_DEFAULT_ENCODING
Type: Dm, Category: I18N (Internationalization)

谁能帮我解释下这个异常,要怎么改呢?
...全文
3122 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
无止进 2013-01-14
  • 打赏
  • 举报
回复
引用 5 楼 is_zhoufeng 的回复:
这里没有说是bug ,只是一个警告而已,并不影响你代码的运行。 你如果不声明编码, 它就会用操作系统默认的编码。 那么你的项目部署到其他服务器上的时候,就有可能发生错误了。 所以他警告你,最好声明一个编码格式。
thank you !
_jerrytiger 2013-01-14
  • 打赏
  • 举报
回复
这里没有说是bug ,只是一个警告而已,并不影响你代码的运行。 你如果不声明编码, 它就会用操作系统默认的编码。 那么你的项目部署到其他服务器上的时候,就有可能发生错误了。 所以他警告你,最好声明一个编码格式。
无止进 2013-01-14
  • 打赏
  • 举报
回复
引用 1 楼 is_zhoufeng 的回复:
提示你最好在 new InputStreamReader(file); 时 ,指定一个编码。 可以这样 InputStreamReader fileData = new InputStreamReader(file ,"utf-8");
试了一下没有BUG了,但为什么那样写会出bug啊,在API 里面不是有这个构造方法的吗,既然这样会出bug为什么还要这个方法呢? 觉得很不理解,能帮我解释下吗?
  • 打赏
  • 举报
回复
InputStreamReader(inputStream),传文件不行吧 InputStreamReader fileData = new InputStreamReader(new FileInputStream(file));
普凡 2013-01-11
  • 打赏
  • 举报
回复
引用 1 楼 is_zhoufeng 的回复:
提示你最好在 new InputStreamReader(file); 时 ,指定一个编码。 可以这样 InputStreamReader fileData = new InputStreamReader(file ,"utf-8");
+1
_jerrytiger 2013-01-11
  • 打赏
  • 举报
回复
提示你最好在 new InputStreamReader(file); 时 ,指定一个编码。 可以这样 InputStreamReader fileData = new InputStreamReader(file ,"utf-8");

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧