sonar代码扫描bug:Use try-with

sonar代码扫描bug:Use try-with

 

 

下面代码

/**
 * 读取文件到byte数组
 *
 * @param tradeFile
 * @return
 */
public static byte[] file2byte(File tradeFile) {
    try {
        FileInputStream fis = new FileInputStream(tradeFile);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] b = new byte[1024];
        int n;
        while ((n = fis.read(b)) != -1) {
            bos.write(b, 0, n);
        }
        fis.close();
        bos.close();
        byte[] buffer = bos.toByteArray();
        return buffer;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » sonar代码扫描bug:Use try-with