zui2jun 2015-04-07 14:21 采纳率: 42.9%
浏览 4456

java web中FileInputStream的路劲老是找不到

用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;    
}

}

  • 写回答

5条回答 默认 最新

  • danielinbiti 2015-04-07 14:44
    关注

    InputStream inp = new FileInputStream("excell/"+excellName+".xlsx");
    这相对路径对吗?打印出来看看。然后看看有没有这个路径,看看System.out.println(new File(".").getAbsolutePath());路径在哪里
    最好加上class的路径比较明确

    评论

报告相同问题?

悬赏问题

  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题