【发布时间】:2015-08-06 05:04:16
【问题描述】:
大家好,我在以下文件夹结构中有 2 个 jar 文件(read.jar、write.jar):
app/read/read.jar
app/write/write.jar
write.jar 将值写入app/important.properties 中的属性文件,read.jar 从app/important.properties 中读取。在 Java 代码中,我使用
FileOutputStream out = new FileOutputStream("/app/important.properties");
这在 Windows 操作系统中运行良好,但是当我将这个 app 放入 Linux 操作系统中时,/home/workspace/app 会抛出 FileNotFoundException。然后我将文件的读取更改为:
FileOutputStream out = new FileOutputStream("./important.properties")
这也产生了FileNotFoundException。任何人都可以帮助我吗?谢谢。
【问题讨论】:
-
确保您使用的是相对路径,因为您的第一个路径是来自根/app 目录的绝对路径
-
你是在读写
important.properties还是height.properties?? -
对不起,我正在阅读重要的.properties 如何在 linux 中给出路径?它总是说找不到文件异常
-
您是否尝试过简单地使用
"important.properties"或"/home/workspace/app/important.properties"? -
在 Windows 中它工作正常,我给了这样的
/app/important.properties但在 linux 中它不工作。
标签: java linux windows properties-file