【发布时间】:2013-09-05 20:33:48
【问题描述】:
我正在尝试读取网络上的文件夹并检索 txt 文件列表。 在 Eclipse 中本地测试它时,它工作正常,但是每当我将它部署在 Apache Tomcat 7 服务器上时,它都会返回 null。
这似乎不是访问权限问题,因为服务器可以访问我尝试浏览的文件夹。 我不确定那里出了什么问题,是我需要更改的服务器上的设置还是其他什么?
private List<File> readDirectory() {
File test = new File(envMap.get(database));
List<File> files = new ArrayList<File>();
try {
files = FileListing.getFileListing(test);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
List<File> txtFiles = new ArrayList<File>();
if (files != null) {
for (File file : files) {
if (file.isFile() && file.getName().endsWith(".txt")) {
txtFiles.add(file);
}
}
}
return txtFiles;
}
我将这个http://www.javapractices.com/topic/TopicAction.do?Id=68 用于FileListing.getFileListing
仔细检查后发现我收到了FileNotFoundException: Directory does not exist。该目录确实存在并且服务器对其具有访问权限,所以我不太确定该怎么做。
【问题讨论】:
-
null是哪一部分?FileListing.getFileListing(test);? -
是的。之后 List
文件为空。它在 Eclipse 中运行良好,所以我认为该功能没有问题。 -
那么你必须向我们展示它是如何实现的。此外,最初将其初始化为
= new ArrayList<File>();也是没有意义的,因为您正在重新分配它。 -
它会抛出 FileNotFound 异常吗?
-
本地 Eclipse 设置和 Tomcat 服务器机器之间的操作系统有何不同?