- Java.util Package Classes
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util Package Extras
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
Java Properties load() Method
Description
The Java Properties load(InputStream inStream) method reads a property list (key and element pairs) from the input byte stream. The input stream is in a simple line-oriented format as specified in load(Reader) and is assumed to use the ISO 8859-1 character encoding; that is each byte is one Latin1 character.
Declaration
Following is the declaration for java.util.Properties.load() method
public void load(InputStream inStream)
Parameters
inStream − the input 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.
Java Properties load(Reader reader) 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(Reader reader) 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.
Loading Properties From a TXT File Example
The following example shows the usage of Java Properties load(InputStream) method to load the properties from a stream.
package com.tutorialspoint; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; public class PropertiesDemo { public static void main(String[] args) { Properties prop = new Properties(); String s = "Height=200"; String s2 = "Width=15"; try { // create a new input and output stream FileOutputStream fos = new FileOutputStream("properties.txt"); FileInputStream fis = new FileInputStream("properties.txt"); // write the first property in the output stream file fos.write(s.getBytes()); // change the line between the two properties fos.write("\n".getBytes()); // write next property fos.write(s2.getBytes()); // load from input stream prop.load(fis); // print the properties list from System.out prop.list(System.out); } catch (IOException ex) { ex.printStackTrace(); } } }
Output
Let us compile and run the above program, this will produce the following result −
-- listing properties -- Width=15 Height=200
Loading Properties From a String Example
The following example shows the usage of Java Properties load(Reader) method to load the properties from a reader.
package com.tutorialspoint; import java.io.IOException; import java.io.StringReader; import java.util.Properties; 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(); } } }
Output
Let us compile and run the above program, this will produce the following result −
-- listing properties -- Width=15 Height=200