java - 在 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();
}
推荐阅读
- c# - Unity iOS 应用程序因不明原因而崩溃
- java - 如何使用 Lambda 和 Streams 查找 2 个单词是否是 Java 中的字谜?
- vue.js - 无法从数据组件填充图表 [vue-highcharts 包装器]
- linux - 我有一个使用 mpicc 编译的技术问题
- python - 为什么这个异常代码输出是 ex 而不是 exex?
- ios - Microsoft App Center 构建失败:多个命令生成“appcenter-pre-build.sh”
- node.js - Gitlab 为每个作业删除并重新安装 node_modules
- keycloak - 如何在 Spring Cloud Gateway 中获取 Keycloak 领域和用户属性
- r - 根据现有的多列在 r 数据框中创建多列
- javascript - webpack-dev-server 无法真正编译 main.js