Java 在jar文件之外获取配置文件?

Java 在jar文件之外获取配置文件?,java,config,Java,Config,我想在.jar文件之外打开一个.config文件,这样我就可以在.jar中使用它的属性。我该怎么做?为了获得许可,您将使用(可执行)jar中的配置文件,如下所示: InputStream in = this.getClass.getResourceAsStream("config.properties"); Properties p = new Properties(); p.load(in); 相对于当前对象的类加载config.properties的 对于外部配置,您可能会使用以下文件:

我想在
.jar
文件之外打开一个
.config
文件,这样我就可以在
.jar
中使用它的属性。我该怎么做?

为了获得许可,您将使用(可执行)jar中的配置文件,如下所示:

InputStream in = this.getClass.getResourceAsStream("config.properties");
Properties p = new Properties();
p.load(in);
相对于当前对象的类加载config.properties的

对于外部配置,您可能会使用以下文件:

InputStream in = new FileInputStream(System.getProperty("user.dir")+"/"+"config.properties");
Properties p = new Properties();
p.load(in);
用这个

String path  = System.getProperty("user.dir")
path += "/config/myApp.properties"
现在您有了属性文件的路径。
您知道下一步要做什么

是的,您可以这样做,首先选择jar文件的路径或安装路径,而不是要加载的属性文件,其中是“超出jar文件的索引”?你能为这个位置建立一个
路径吗?我得到文件未报告的异常FileNotFoundException;必须捕获或声明要抛出。这不是一个完整的示例。异常处理是为您准备的。