Set Properties in Text with Java

On May 4, 2013, in Java, Programming, by LuCuS

Set properties in text with Java.

PropertyManager.java

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Properties;

public class PropertyManager
{
	public static void setProperties (List<String[]> values)
	{
		Properties properties = new Properties();
		try
		{
			for (String[] value : values)
			{
				properties.setProperty(value[0], value[1]);
			}
			properties.store(new FileOutputStream("config.properties"), null);
		}
		catch (IOException ioe)
		{
			
		}
	}
}

Test.java

import java.util.ArrayList;
import java.util.List;

public class Test
{
	public static void main (String[] args)
	{
		List<String[]> properties = new ArrayList<String[]>();
		properties.add(new String[]{ "PROPERTY_1", "This is property 1."});
		properties.add(new String[]{ "PROPERTY_2", "This is property 2."});
		PropertyManager.setProperties(properties);
	}
}

Thank you for your interest in my site. If you find the information provided on this site useful, please consider making a donation to help continue development!

PayPal will open in a new tab.
$2.00
$5.00
Other

Related Posts

Tagged with:  

Leave a Reply