Java relative file path

I have a Java problem that I've been having trouble with: what's a good way to indicate relative file paths

Let me be more specific I wish I could always be there/ configuration/file. Txt The problem I have is that my program can work only if it is started from the directory where the file is located If I start it from another directory, such as/ directory/to/my/program/execute. SH then it doesn't work properly

But I still need to make changes to this file. The resource seems to want to be read-only

Solution

The recommended way to read configuration information (making the application independent of environment specific details) is to read it as a classpath resource rather than a file system resource Read smartly load your properties for more details

For syntax on how to specify a resource path, read class getResourceAsStream javadoc

Useful posts about so: classpath resource within jar

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>