What is the best way to serialize Delphi application configuration?

后端 未结 7 1750
猫巷女王i
猫巷女王i 2021-02-02 02:21

I will answer this question myself, but feel free to provide your answers if you are faster than me or if you don\'t like my solution. I just came up with this idea and would li

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-02 02:50

    This would be for Java.

    I like to use the java.util.Properties class for reading in config files or properties files. What I like is that you put your file with lines in the same way you showed above (key=value). Also, it uses a # (pound sign) for a line thats a comment, kind of like a lot of scripting languages.

    So you could use:

    ShowFlags=true
    # this line is a comment    
    NumFlags=42
    

    etc

    Then you just have code like:

    Properties props = new Properties();
    props.load(new FileInputStream(PROPERTIES_FILENAME));
    String value = props.getProperty("ShowFlags");
    boolean showFlags = Boolean.parseBoolean(value);
    

    Easy as that.

提交回复
热议问题