Properties void load(InputStream inStream) method Example Program


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. Characters not in Latin1, and certain special characters, are represented in keys and elements using Unicode escapes as defined in section 3.3 of The Java? Language Specification.
The specified stream remains open after this method returns.

Program

package com.candidjava;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
/* 
 * @author : Mohan 
 * @description : The java.util.Properties.load(InputStream inStream) method reads a property list (key and element pairs) from the input byte stream. 
 */
public class PropertiesLoadInputStream {
	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

-- listing properties --
Width=15
Height=200

Explanation

public void load(InputStream inStream) throws IOException
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. Characters not in Latin1, and certain special characters, are represented in keys and elements using Unicode escapes as defined in section 3.3 of The Java? Language Specification.
The specified stream remains open after this method returns.

Parameters:
inStream - the input stream.
Throws:
IOException - if an error occurred when reading from the input stream.
IllegalArgumentException - if the input stream contains a malformed Unicode escape sequence.
Since:
1.2


Related Post

Comments


©candidjava.com