10:24 pm - Monday March 27, 2017

Properties example program using load from xml(InputStream in)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This Properties example program id used load from xml using xml(InputStream in) method.

Example Program

import java.io.*;

import java.util.*;

public class PropLoadForm {

	public static void main(String[] args) throws IOException {

		Properties prop = new Properties();

		prop.put("Dhoni", "cricket");

		prop.put("nadal", "tennis");

		prop.put("cena", "wwe");

		try {

			FileOutputStream fos = new FileOutputStream("properti.xml");

			FileInputStream fis = new FileInputStream("properti.xml");

			prop.storeToXML(fos, null);

			prop.loadFromXML(fis);

			prop.list(System.out);

		} catch (Exception e) {

			System.out.println(e);

		}

	}

}

 

Output

– listing properties –

cena=wwe

Dhoni=cricket

nadal=tennis

 

Explanation

public void loadFromXML(InputStream in)throws IOException,InvalidPropertiesFormatException

Loads all of the properties represented by the XML document on the specified input stream into this properties table.

The XML document must have the following DOCTYPE declaration:

<!DOCTYPE properties SYSTEM “http://java.sun.com/dtd/properties.dtd”>

Furthermore, the document must satisfy the properties DTD described above.

The specified stream is closed after this method returns.

 

Parameters:

in – the input stream from which to read the XML document.

 

Throws:

IOException – if reading from the specified input stream results in an IOException.

InvalidPropertiesFormatException – Data on input stream does not constitute a valid XML document with the mandated document type.

NullPointerException – if in is null.

 

Since:

1.5

 

See Also:

storeToXML(OutputStream, String, String)

BACK

 

Filed in: Z-A All Java Codes

Comments are closed.