关于在配置文件中配置参数的问题

现在有个需求,就是解析excel文件,然后倒入数据库。

其他的都写好了,现在我想定义一个文件夹file,把写好的应用程序打包,执行bat文件的时候能自动的检测file目录下面的xls文件,从而遍历xls文件进行操作。
现在的问题是这个file放在什么地方?在程序中怎么取到他的地址?
public class IntegralBalanceToDB {
public static void main(String args[]) {
//怎么取到file目录的位置?

     ....
     }

}

[code="java"]
String path = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); //获取jar路径
String file = this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile(); //获取jar文件名
[/code]
例如我放到桌面的jar包,获取到的路径如下:
[img]http://dl.iteye.com/upload/picture/pic/90487/afc248ed-54c7-3f46-ae59-abbdf121fd2c.png[/img]

[code="java"]
public List getFilePathList(File file) {

List filePathList = new ArrayList();

File[] list = file.listFiles();

if (list != null) {

for (File file2 : list) {

if (file2.isDirectory()) {

filePathList.addAll(getFilePathList(file2));

} else {

if(file2.getPath().endWith(".xls")) {
filePathList.add(file2.getPath());

count++;

}
}

}

}

return filePathList;

}

[/code]
然后调用getFilePathList(new File("file文件夹的路径"))得到所有xls文件的绝对路径。
后面执行你操作xls部分的逻辑即可。

poi读取可以吗

[code="java"]// 构造 XSSFWorkbook 对象,path 传入文件路径
XSSFWorkbook xwb = new XSSFWorkbook(path);
// 读取第一章表格内容
XSSFSheet sheet = xwb.getSheetAt(0);
// 定义 row、cell
XSSFRow row;
String cell;
// 循环输出表格中的内容
for (int i = sheet.getFirstRowNum(); i < sheet.getPhysicalNumberOfRows(); i++) {
row = sheet.getRow(i);
for (int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++) {
// 通过 row.getCell(j).toString() 获取单元格内容,
cell = row.getCell(j).toString();
System.out.print(cell + "\t");
}
System.out.println("");
}[/code]

可将其放在包外,用System.getProperty("user.dir");获取的是打完包的程序所在的位置,file目录此时用相对路径就可以了;
也可将其放入包内,用Class类的public URL getResource(String name)方法返回当前类所在的方法

web项目的话使用 getClass().getResourceAsStream(filePath)