用POI操作excell,但是文件路劲老找不到 ,应该怎么写啊
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.application.Application;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jboss.weld.context.ApplicationContext;
public class ExcellInfo {
private Map allSheet=new HashMap();
public Map<String, List> getAllSheet() {
return allSheet;
}
public void setAllSheet(Map<String, List> allSheet) {
this.allSheet = allSheet;
}
public String getInfo() throws IOException{
System.out.println(this.getClass().getClassLoader().getResource("").getPath());
allSheet = getAllSheet("上海某购物中心");
return "ok";
}
public Map<String,List> getAllSheet(String excellName) throws IOException{
Map<String,List> allSheet=new HashMap<String,List>();
List<List> list = null;
List<String> context = null;
InputStream inp = new FileInputStream("excell/"+excellName+".xlsx");
XSSFWorkbook wb = new XSSFWorkbook(inp);
for (int i = 0; i < wb.getNumberOfSheets(); i++) {
Sheet sheet = wb.getSheetAt(i);
list = new ArrayList<List>();
for (Row row : sheet) {
context = new ArrayList<String>();
for (Cell cell : row) {
context.add(cell.toString());
}
list.add(context);
}
allSheet.put(sheet.getSheetName(), list);
}
return allSheet;
}
}