[英]How to add directory to classpath in an application run profile in IntelliJ IDEA?
[英]Add directory to classpath in IntelliJ
我正在尝试运行我的主类并将其他属性文件添加到类路径中,但它没有发生。 我看到了一些解决方案,如链接,但它们对我不起作用。 我还尝试将“-cp \\path to property files”添加到“运行配置”->“VM 选项”中,但同样没有成功。
如果我对你的理解正确,如果你不想从现有文件中读取,你必须先创建文件,然后用类似于下面的内容写入它:
try {
File f = new File("path/to/propertyFile.properties");
if (file.createNewFile()){
// some debugging
System.out.println("File is created!");
}else{
System.out.println("File already exists.");
}
// you have your file now, and you can perform manipulations to it
OutputStream output = new FileOutputStream("path/to/propertyFile.properties")
Properties prop = new Properties();
prop.setProperty("key", "value");
// save properties to project root folder
prop.store(output, null);
} catch (IOException io) {
io.printStackTrace();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.