【发布时间】:2012-12-13 18:45:56
【问题描述】:
我正在尝试创建一个File 对象以保存我的属性文件。我需要知道如何从我的包中指定相对路径,因为下面的代码不起作用。
try {
File file = new File(new File(Thread.currentThread().getContextClassLoader().getResource("").toURI()), "com/configuration/settings.properties");
try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
properties.store(fileOutputStream, null);
}
} catch (IOException | URISyntaxException ioe) {
System.out.println(ioe);
}
【问题讨论】:
标签: java file properties package relative-path