Class ModifiableProperties

  • All Implemented Interfaces:
    Serializable, Cloneable, Map<Object,​Object>

    public class ModifiableProperties
    extends Properties
    Modified from original source: https://www.dreamincode.net/forums/topic/53734-java-code-to-modify-properties-file-and-preserve-comments/
    Author:
    Walt F - https://www.dreamincode.net/forums/user/320878-waltf/, Brian Wyka
    See Also:
    Serialized Form
    • Constructor Detail

      • ModifiableProperties

        public ModifiableProperties()
    • Method Detail

      • create

        public static ModifiableProperties create​(InputStream inputStream)
                                           throws IOException
        Create an instance and load the input stream
        Parameters:
        inputStream - the input stream to load
        Returns:
        the properties
        Throws:
        IOException - if an error occurs loading the input stream
      • load

        public void load​(InputStream inputStream)
                  throws IOException
        Load properties from the specified InputStream. Overload the load method in Properties so we can keep comment and blank lines.
        Overrides:
        load in class Properties
        Parameters:
        inputStream - the input stream to read
        Throws:
        IOException
      • store

        public void store​(Writer writer,
                          String header)
                   throws IOException
        Write the properties to the specified OutputStream.

        Overloads the store method in Properties so we can put back comment and blank lines.

        Overrides:
        store in class Properties
        Parameters:
        writer - the writer to use for storing
        header - Ignored, here for compatibility w/ Properties.
        Throws:
        IOException
      • add

        public void add​(String keyString,
                        String value)
        Add a Property to the end of the CommentedProperties.
        Parameters:
        keyString - The Property key.
        value - The value of this Property.
      • addLine

        public void addLine​(String line)
        Add a comment or blank line or comment to the end of the CommentedProperties.
        Parameters:
        line - The string to add to the end, make sure this is a comment or a 'whitespace' line.