【发布时间】:2013-08-10 01:59:20
【问题描述】:
这是我第一次在 Linux 上遇到 Java 文件访问这样的问题。问题就像标题所说的那样 - 当文件实际存在时抛出FileNotFoundException。此外,具有相同配置(props.txt 文件)的应用程序可以像在 Windows 上一样运行。
让我提供一点控制台输出
这是负责生成该输出的 Java 代码(至少在调用 ./propsUpdate 之后)
private void readProperties(String args) throws FileNotFoundException, IOException {
System.out.println("Parent: " + new File(args).getAbsoluteFile().getParentFile().getAbsolutePath());
CommonTools.PrintArray(new File(args).getAbsoluteFile().getParentFile().list());
properties.load(new FileInputStream(new File(args).getAbsoluteFile())); // this line throws the exception
stageNumber = Integer.parseInt(properties.getProperty(PROP_STAGE_NUMBER_KEY, "0"));
}
那么为什么props.txt 文件实际存在时却找不到呢?
【问题讨论】:
-
正确的路径真的是
/usr/home/datasu/吗?我不知道您的 linux/unix 版本,但它通常不是在/home/...上吗?特别是因为您在第一行显示了~/,它引用了主目录。 -
这是您的 PWD 结果:datasu@dedi2392:~/netcrawler/dkpto$ pwd -> /usr/home/datasu/netcrawler/dkpto
-
您传递给
readProperties的args的确切语法是什么? -
尝试将
FileInputStream与new File分开,就像这样:File file = new File(args)file = file.getAbsoluteFile()FileInputStream fis = new FileInputStream(file)这样我们可以获得更多信息