jenkins findbugs流編碼問題:DM_DEFAULT_ENCODING


報錯信息:

MessageParserUtil.java:122, DM_DEFAULT_ENCODING, Priority: High

Dm: Found reliance on default encoding in com.huawei.nos.nosimsys.parser.MessageParserUtil.parse(File): new java.io.FileReader(File)

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.

翻譯:

找到一個方法的調用,它將執行一個字節到字符串(或字符串到字節)的轉換,並假定默認的平台編碼是合適的。這會導致應用程序行為在不同平台之間變化。使用替代API並明確指定字符集名稱或字符集對象

源代碼:

1
2
//FileReader fileReader = new FileReader(file);
//BufferedReader br = new BufferedReader(fileReader);

改為:

1
2
InputStreamReader isr =  new  InputStreamReader( new  FileInputStream(file),  "UTF-8" );
BufferedReader br =  new  BufferedReader(isr);
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM