日期:2014-05-20  浏览次数:20733 次

findBugs 这个报的是什么异常
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)

谁能帮我解释下这个异常,要怎么改呢?

------解决方案--------------------
提示你最好在  new InputStreamReader(file); 时 ,指定一个编码。

可以这样  InputStreamReader fileData = new InputStreamReader(file ,"utf-8"); 
------解决方案--------------------
引用:
提示你最好在  new InputStreamReader(file); 时 ,指定一个编码。

可以这样  InputStreamReader fileData = new InputStreamReader(file ,"utf-8");



+1            
------解决方案--------------------
InputStreamReader(inputStream),传文件不行吧
InputStreamReader fileData = new InputStreamReader(new FileInputStream(file));