My problem is a bit different from the ones that are there in SO...I will try to explain..
My code pick up an .xls
file from a location (c:\codereview\
) and inserts data into that file. I was using full file path for this but realized my program is not portable.
So I copied my xls
from c:/
drive into the src/
folder and I now I keep getting a FileNotFoundException
.
FileInputStream file = new FileInputStream(new File("/src/New_Record.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheetAt(0);
when i try to use:
FileInputStream file = (FileInputStream) Util.class.getResourceAsStream("New_Record.xls");
i get below exception:
java.lang.NullPointerException at org.apache.poi.poifs.filesystem.POIFSFileSystem.closeInputStream(POIFSFileSystem.java:183) at org.apache.poi.poifs.filesystem.POIFSFileSystem.(POIFSFileSystem.java:145) at org.apache.poi.hssf.usermodel.HSSFWorkbook.(HSSFWorkbook.java:322) at org.apache.poi.hssf.usermodel.HSSFWorkbook.(HSSFWorkbook.java:303)
Basically I want to use a combination of FileInputStream and InputStream so that i can use that with HSSFWorkbook. InputStream is not compatible directly with it and FileInputStream is not compatible with this.getClass.getResourceStream.