I am facing an issue where everytime path is initialized to XSSFWorkbook, a file java.io.FileInputStream@51bde877 (51bde877 being a random number each time) is created in the root folder of my project. Below is the sample code:
try {
fis = new FileInputStream(path);
if (path.endsWith(".xls")) {
workbook = new HSSFWorkbook(fis);
}
if (path.endsWith(".xlsx")) {
workbook = new XSSFWorkbook(path);
}
if (rowNum <= 0)
return false;
int index = workbook.getSheetIndex(sheetName);
if (index == -1)
return false;
sheet = workbook.getSheetAt(index);
int colNum = -1;
row = sheet.getRow(0);
for (int i = 0; i < row.getLastCellNum(); i++) {
// System.out.println(row.getCell(i).getStringCellValue().trim());
if (row.getCell(i).getStringCellValue().trim().equals(colName))
colNum = i;
}
if (colNum == -1)
return false;
sheet.autoSizeColumn(colNum);
row = sheet.getRow(rowNum - 1);
if (row == null)
row = sheet.createRow(rowNum - 1);
cell = row.getCell(colNum);
if (cell == null)
cell = row.createCell(colNum);
cell.setCellValue(data);
//fis.close();
fileOut = new FileOutputStream(String.valueOf(new FileInputStream(path)));
workbook.write(fileOut);
fileOut.flush();
workbook.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
How should I prevent the creation of these junk files in my project?