当文件存在所有权限时FileNotFoundException [英] FileNotFoundException when file exists with all permissions
问题描述
我正在尝试读取一个文件,并且我得到的错误是
I am trying to read a file and the error i get is
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的权限,如下所示:
however the file does exist and just to double check i gave it 777 permissions, as shown below:
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
任何想法,为什么我得到FNF异常?
Any ideas as to why I'm getting the FNF exception?
感谢
拨打电话的java代码:
java code that makes the call:
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
(使用diff pathToConfiguration(传递给构造函数))并且正常工作。
This was tested in windows (with a diff pathToConfiguration (which is passed into the constructor)) and works fine.
在Catch块中的以下检查中添加
Added in the following checks in the Catch block
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
推荐答案
根据初始堆栈跟踪似乎是文件名和原因之间的两个空格:
According to the initial stacktrace there appear to be two spaces between the file name and reason:
FileNotFoundException: ...Configuration.properties (No such file or directory)
--------------------------------------------------^^
这将告诉我文件名可能有一个尾随空格。您可以通过以下方式仔细检查您的pathToConfiguration变量:
This would indicate to me that the filename possibly has a trailing space. Can you double check your pathToConfiguration variable by:
System.out.println("[" + pathToConfiguration + "]");
重复检查路径是否符合您的想法?
To double check that the path is what you think it is?
这篇关于当文件存在所有权限时FileNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!