0

設定ファイルについて質問があります。次のようにJavaで作成することは可能ですかfile.properties(Apache Commons Configurationの例):

name = tom
surname = donald
free string = my favourite color is + paramFromJavaCode

paramFromJavaCodeは Java コードから動的に設定されますか? 私は明確だったと思います、ありがとう。

4

2 に答える 2

0

プログラムで .properties ファイルを作成しようとしていると仮定すると、この方法で作成できます。マーモット文字列に何かを追加する方法に関するセクションを追加しました。ただし、これは非常に基本的な Java 文字列操作です。

public class WritePropertiesFile {
    public static void main(String[] args) {

        String customString = " are great!";

        try {
            Properties properties = new Properties();
            properties.setProperty("favoriteAnimal", "marmot" + customString);
            properties.setProperty("favoriteContinent", "Antarctica");
            properties.setProperty("favoritePerson", "Nicole");

            File file = new File("test2.properties");
            FileOutputStream fileOut = new FileOutputStream(file);
            properties.store(fileOut, "Favorite Things");
            fileOut.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

どちらが出力されますか

#Favorite Things
#Sat Feb 24 00:10:53 PST 2007
favoriteContinent=Antarctica
favoriteAnimal=marmot are great!
favoritePerson=Nicole
于 2014-11-28T14:54:49.863 に答える