在Excel POI上制定具体的path

我想制作一个保存在数据库中的path。
这是我的代码。

@RequestMapping("import_excel") @ResponseBody public Map<String, ? extends Object> import_excel() { modelMap.clear(); try { HttpSession session = req.getSession(); HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Export"); Row row1 = sheet.createRow((short) 3); row1.createCell(0).setCellValue("Asset Number"); row1.createCell(1).setCellValue("Asset Barcode"); row1.createCell(2).setCellValue("Asset Name"); short i = 4; Row row2 = sheet.createRow(i++); row2.createCell(0).setCellValue(as.getCdas()); row2.createCell(1).setCellValue(as.getBcd()); row2.createCell(2).setCellValue(as.getNm()); FileOutputStream fileOut = new FileOutputStream(src + "/Export.xls"); wb.write(fileOut); fileOut.close(); modelMap.put("success", true); modelMap.put("rows", obj); modelMap.put("count", count); } catch (IOException ex) { modelMap.put("success", false); modelMap.put("msg", ex.getMessage()); } return modelMap; } 

我想让FileOutputStream fileOut = new FileOutputStream(src +“/Export.xls”);
与我保存在数据库中的path。 所以如果我想改变path,我只是在数据库中更改。
我试过上面的代码,但似乎不工作。
请帮帮我。 谢谢 :)

我会build议以编程方式使用它…

使用

 String PathTillProject = System.getProperty("user.dir"); 

这会给你的系统path一级到src即直到你的项目(我假设你的src只是在你的项目目录中)。 例如,如果您的项目名称是TestProject则位置或srcTestProject/src 。 现在你可以像这样使用它:

 String PathTillProject = System.getProperty("user.dir"); FileOutputStream fileOut = new FileOutputStream(PathTillProject + "/src/Export.xls");