⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getinformation.java

📁 java阿里巴巴代码
💻 JAVA
字号:
/**
 * @(#) GetInformation.java
 * @version 1.0.1
 */

package tools.util;

import java.io.InputStream;
import java.util.Properties;
import java.util.ResourceBundle;

/**
 * get db or page or other properties from properties file
 * the properties file must be found from classpath, that is to say:
 * You should put the property file's directory in system's 'classpath'
 *
 * Such as: if the property file seems c:\work\hgs\java\db.properties
 * you should put c:\work\hgs\java in your classpath
 */
 
public class GetInformation
{
	public Properties prop;
	
	public GetInformation(String name)
	{
		String fileName = name.trim();
		init(fileName);
	}
	
	private void init(String name)
	{
		InputStream is = getClass().getClassLoader().getResourceAsStream(name);		
		prop = new Properties();
		
		try 
		{
			prop.load(is);
		}
		catch (Exception e) 
		{
			System.err.println("Can't read from property file: " + name +
								".Make sure that the file is under proper path");
			return;
		}
	}
	
	public String getProperty(String propName)
	{
		String propValue = "";
		propValue = prop.getProperty(propName);
		if(propValue == null)
		{
			System.out.println("Please check the property name '" + propName + "' and try it again");
			propValue = "";
		}
		return propValue;
	}
	

	/**
	 * getPropFromBundle, get property value
	 * @param String filename, if file is 'db.properties', use 'db' directly
	 * @param String prop, property name
	 * @return String, property value 
	 */	
	public static String getPropFromBundle(String filename, String prop)
	{
		try{
			ResourceBundle resources = ResourceBundle.getBundle(filename);
			return resources.getString(prop);
		}
		catch (java.util.MissingResourceException e)
		{
			e.printStackTrace();
			return "";
		}
	}
	
	public static void main(String[] argv)
	{
		System.out.println(getPropFromBundle("db", argv[0]));
		System.out.println("This is a test");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -