FileNotFoundException when file exists with all permissions [duplicate]

二次信任 提交于 2019-12-03 12:05:45

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)
--------------------------------------------------^^

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?

I suppose you double checked the pathname more than once, and as you say you are running the app on the same machine where the code resides.

Could it be that there are some obscure NFS/file server mounts that are valid only for the login shell but not for the applications?

Try copying the file in your $HOME and see if it works.

What gets outputted if you write this:

System.out.println(new File(".").getAbsolutePath());

what is your current directory?

When you execute your java program are you running it as the same 'user' as when you run the command-line checks?

EDIT: Try copying the file to the directory where you run your program from and see if it is able to read it. You can also try the following after copying the file to your execution directory:

InputStream in = getClass().getResourceAsStream("/gameTheoryAgentConfiguration.properties");
configuration.load(in);

(assuming you have "." in your classpath)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!