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)谁能帮我解释下这个异常,要怎么改呢?

解决方案 »

  1.   

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

  2.   

    InputStreamReader(inputStream),传文件不行吧
    InputStreamReader fileData = new InputStreamReader(new FileInputStream(file)); 
      

  3.   

    试了一下没有BUG了,但为什么那样写会出bug啊,在API 里面不是有这个构造方法的吗,既然这样会出bug为什么还要这个方法呢? 觉得很不理解,能帮我解释下吗?
      

  4.   

    这里没有说是bug ,只是一个警告而已,并不影响你代码的运行。
    你如果不声明编码, 它就会用操作系统默认的编码。 那么你的项目部署到其他服务器上的时候,就有可能发生错误了。 所以他警告你,最好声明一个编码格式。