CORE API / NOTES</>↗Core API18 Nov 2007
In the previous example, How do I load properties from XML file? we read properties from XML file. Now it’s the turn on how to store the properties as XML file. package org.kodejava.io; import java.io.FileOutputStream; import java.nio.charset.StandardCharsets; import java.util.Properties; public class PropertiesToXml { public static void main(String[] args) throws Exception { Properties properties = new […]
CORE API / NOTES</>↗Core API16 Nov 2007
Reading XML properties can be easily done using the java.util.Properties.loadFromXML() method. Just like reading the properties from a file that contains a key=value pairs, the XML file will also contain a key and value wrapped in the following XML format. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>Application Configuration</comment> <entry key="data.folder">D:\AppData</entry> <entry key="...
CORE API / NOTES</>↗Core API13 Nov 2007
This example will show you how to convert an InputStream into String. In the code snippet below we read a data.txt file, could be from common directory or from inside a jar file. package org.kodejava.io; import java.io.*; import java.nio.charset.StandardCharsets; public class StreamToString { public static void main(String[] args) throws Exception { StreamToString demo = new […]
CORE API / NOTES</>↗Core API11 Nov 2007
Here you will find how to convert string into java.io.InputStream object using java.io.ByteArrayInputStream class. package org.kodejava.io; import java.io.*; import java.nio.charset.StandardCharsets; public class StringToStream { public static void main(String[] args) { String text = "Converting String to InputStream Example"; // Convert String to InputStream using ByteArrayInputStream // class. This class constructor takes the string byte array […]
APACHE COMMONS / NOTES</>↗Apache Commons08 Nov 2007
Using the PropertyUtils.getPropertyType() we can determine the bean property type. This method return a Class object of bean’s property type. package org.kodejava.commons.beanutils; import org.apache.commons.beanutils.PropertyUtils; import org.kodejava.commons.beanutils.support.Record; public class PropertyType { public static void main(String[] args) { Record record = new Record(); record.setTitle("Magical Mystery Tour"); try { /* * Using PropertyUtils.getPropertyType() to d...
APACHE COMMONS / NOTES</>↗Apache Commons03 Nov 2007
In this example you’ll see how to read mapped property value of a bean. We use PropertyUtils.getMappedProperty() method the read the mapped property of the Record object that consist of Track objects. package org.kodejava.commons.beanutils; import org.apache.commons.beanutils.PropertyUtils; import org.kodejava.commons.beanutils.support.Track; import org.kodejava.commons.beanutils.support.Record; import java.util.HashMap; import java.util.Map; public class ReadMapProperty { pu...