Java.util.Properties.load() Method



Description

The java.util.Properties.load(Reader reader) method Reads a property list (key and element pairs) from the input character stream in a simple line-oriented format.

Declaration

Following is the declaration for java.util.Properties.load() method

public void load(Reader reader)

Parameters

reader − the input character stream.

Return Value

This method does not return a value.

Exception

  • IOException − if an error occurred when reading from the input stream.

  • IllegalArgumentException − if the input stream contains a malformed Unicode escape sequence.

Example

The following example shows the usage of java.util.Properties.list() method.

package com.tutorialspoint;

import java.io.IOException;
import java.io.StringReader;
import java.util.*;

public class PropertiesDemo {
   public static void main(String[] args) {
      Properties prop = new Properties();
      String s = "Height=200\nWidth=15";

      // create a new reader
      StringReader reader = new StringReader(s);

      try {
         // load from input stream
         prop.load(reader);

         // print the properties list from System.out
         prop.list(System.out);
      } catch (IOException ex) {
         ex.printStackTrace();
      }
   }
}

Let us compile and run the above program, this will produce the following result −

-- listing properties --
Width=15
Height=200
java_util_properties.htm
Advertisements