簡體   English   中英

將目錄添加到 IntelliJ 中的類路徑

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM