将目录添加到IntelliJ中的类路径中

问题描述 投票:0回答:1

我正在尝试运行我的主类并将其他属性文件添加到类路径中,但这没有发生。我看到了一些解决方案,例如link,但它们对我不起作用。我还尝试将“ -cp \到属性文件的路径”添加到“运行配置”->“ VM选项”,但再次失败。

java intellij-idea classpath
1个回答
0
投票

如果我对您的理解正确,如果您不想从现有文件中读取文件,则必须先创建该文件,然后以类似以下的方式写入该文件:

    try {
        File f = new File("path/to/propertyFile");
        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 prop = new Properties();

        // save properties to project root folder
        prop.store(output, null);

    } catch (IOException io) {
        io.printStackTrace();
    }
© www.soinside.com 2019 - 2024. All rights reserved.