这是我的代码,它读取excelsheet文件。但是我可以看到我的其他函数工作正常但是当尝试获取资源作为url时它返回null。
URL resource = null;
try {
System.out.println(file3);
resource = getServletContext().getResource(file3);
System.out.println("Problem with getting resource"+resource);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
File file = null;
try {
System.out.println(resource.toURI());
file = new File(resource.toURI());
} catch (URISyntaxException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
FileInputStream input = null;
try {
input = new FileInputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Workbook w;
w = Workbook.getWorkbook(input);
// Get the first sheet
Sheet sheet = w.getSheet(0);
return sheet;