All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.becausetesting.properties.PropertyUtils Maven / Gradle / Ivy

There is a newer version: 1.1.3
Show newest version
package com.github.becausetesting.properties;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;

public class PropertyUtils {

	private static ResourceBundle resourceBundle;
	private static Properties properties = new Properties();
	
	//**********************using resourcebundle********************************************
	
	public static void setResourceBundle(File propertyfile) {
		String filename = propertyfile.getName();
		int pos=filename.lastIndexOf(".");
		if(pos>0){
			filename=filename.substring(0, pos);
		}
		ResourceBundle tempresourceBundle = ResourceBundle.getBundle(filename, Locale.getDefault());
		//InputStream propertyresource = PropertyUtils.class.getClassLoader().getResourceAsStream(propertyfile+".properties");
		try {
			properties.load(new FileInputStream(propertyfile));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		resourceBundle = tempresourceBundle;
	}
	
	public static String getBundleString(String key){
		return resourceBundle.getString(key);
	}

	public static String setBundleString(String key,String value){
		return resourceBundle.getString(key);// ????
	}

	
	//**********************using resourcebundle********************************************
	
	
	//**********************using property********************************************
	public static String getPropertyString(String key){
		return properties.getProperty(key);
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy