FileNotFoundException时文件存在与所有权限[重复]
-
22-09-2019 - |
题
这个问题已经有一个答案在这里:
我试图阅读一个文件和错误我得到的是
java.io.FileNotFoundException: /homes/at1106/fourthYearComputing/Individual-Project/svn-workspace/trunk/Individual_Project/src/game/player/gametheoryagent/configurations/gameTheoryAgentConfiguration.properties (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at game.player.gametheoryagent.GameTheoryAgent.<init>(GameTheoryAgent.java:67)
at simulation.Simulator.createPlayer(Simulator.java:141)
at simulation.Simulator.main(Simulator.java:64)
然而该文件不存在,只是仔细检查我给它777权限,如下所示:
tui% cd /homes/at1106/fourthYearComputing/Individual-Project/svn-workspace/trunk/Individual_Project/src/game/player/gametheoryagent/configurations
tui% ls -al
total 4
drwxrwxrwx 3 at1106 cs4 1024 2010-02-22 17:45 .
drwxrwxrwx 4 at1106 cs4 1024 2010-02-22 17:27 ..
-rwxrwxrwx 1 at1106 cs4 260 2010-02-22 17:31 gameTheoryAgentConfiguration.properties
drwxrwxrwx 6 at1106 cs4 1024 2010-02-22 17:41 .svn
任何想法为什么我得到的善保异常?
感谢
java代码,使得呼吁:
File file = new File(pathToConfiguration)
Properties configuration = new Properties();
try{
configuration.load(new FileInputStream(file));
int RAISE_RATIO = Integer.parseInt(configuration.getProperty("raise_ratio"));
}
catch(IOException event){
System.err.println("Error in reading configuration file " + pathToConfiguration);
event.printStackTrace();
}
属性文件如下:
raise_ratio=4
这是测试在窗户(有差异pathToConfiguration(其是通过入constructor))和工作的罚款。
加入以下检查在赶块
if(file.exists()){
System.out.println("file exists");
}
else{
System.out.println("file doesn't exist");
}
System.out.println(file.getAbsolutePath());
if(file.canRead()){
System.out.println("can read");
}
if(file.canWrite()){
System.out.println("can write");
}
输出如下:
file doesn't exist
/homes/at1106/fourthYearComputing/Individual-Project/svn-workspace/trunk/Individual_Project/src/game/player/gametheoryagent/configurations/gameTheoryAgentConfiguration.properties
解决方案
根据初始堆栈跟踪有出现两个空间之间的文件名称和原因:
FileNotFoundException: ...Configuration.properties (No such file or directory)
--------------------------------------------------^^
这将表明的,我认该文件可能有一个后空间。你能仔细检查你的pathToConfiguration变量:
System.out.println("[" + pathToConfiguration + "]");
仔细检查,路径是什么你认为是什么?
其他提示
我想你一双重检查路径超过一次,你说你正在运行的应用程序在相同的计算机代码所在。
它可能是有一些模糊的NFS/文件服务器支架,这是只适用于登录的外壳,但没有为这些应用程序?
试图将文件复制在你家看看是否它的工作。
什么得到输出的,如果你写这样的:
System.out.println(new File(".").getAbsolutePath());
什么是当前的目录?
当你执行你的java程序是你的行为相同的"用户",作为在运行命令行检查?
编辑:试图复制文件的目录,其中运行的程序,从而查看它是否能够阅读。你也可以尝试下列后将文件拷贝到你执行目录:
InputStream in = getClass().getResourceAsStream("/gameTheoryAgentConfiguration.properties");
configuration.load(in);
(假定你有"。"此类路径)
不隶属于 StackOverflow