欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SpringBoot读取jar包中的静态资源文件

程序员文章站 2022-04-28 09:21:34
...
final String fileSeparator = File.separator;
try {
    InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("static" + fileSeparator + "test.xlsx");
    Workbook wb = new XSSFWorkbook(inputStream);
    //开始解析
    Sheet sheet = wb.getSheetAt(0);//读取sheet0
    int firstRowIndex = sheet.getFirstRowNum() + 1;//第一行是列名,所以不读
    int lastRowIndex = sheet.getLastRowNum();
    for (int rIndex = firstRowIndex; rIndex <= lastRowIndex; rIndex++) {//遍历行
        Row row = sheet.getRow(rIndex);
        if (row != null) {
            xgb_indexerMap.put(row.getCell(1) + "_" + new Integer(Double.valueOf(row.getCell(2).toString()).intValue()).toString(), new Integer(Double.valueOf(row.getCell(3).toString()).intValue()).toString());
        }
    }
} catch (Exception e) {
    log.error("load file fail,message:{}", e);
}
相关标签: 实操