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

📄 config.java

📁 网络硬盘
💻 JAVA
字号:
package com.zte.webfile.conf;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * 此类用于读取配置文件
 * 
 * @author kwatt
 * 
 */
public class Config {
	private final static Logger log=Logger.getLogger(Config.class);
	/**
	 * 读取配置文件中的字符串
	 * 
	 * @param key
	 *            字符串名称
	 * @return key所对应的value
	 */
	public static String getValue(String key,String proName) {
		Properties pro = new Properties();
		// 返回的字符串
		String value = new String();
		String path=Config.getPath("WebRoot\\");
		try {
			pro.load(new FileInputStream(path+proName));
			value=pro.getProperty(key);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return value;
	}
	public static String getClassValue(String key,String proName) {
		Properties pro = new Properties();
		// 返回的字符串
		String value = new String();
		String path=Config.getClassPath("webfile\\");
		try {
			pro.load(new FileInputStream(path+proName));
			value=pro.getProperty(key);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return value;
	}
//	public static String getValue1(String key,String proName) {
//		Properties pro = new Properties();
//		// 返回的字符串
//		String value = new String();
//		String path=Config.getClassPath("WebRoot\\");
//		try {
//			pro.load(new FileInputStream(path+proName));
//			value=pro.getProperty(key);
//		} catch (FileNotFoundException e) {
//			e.printStackTrace();
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//		return value;
//	}
/**
 * 获得绝对路径
 * @param userPath 用户路径
 * @return 绝对路径
 */
	public static String getPath(String userPath){
		String rootPath=System.getProperty("user.dir");
		String path=rootPath+"\\"+userPath;
		return path;
	}
	/**
	 * 获得Class路径
	 * @param classPath 
	 * @return Class路径
	 */
	public static String getClassPath(String classPath){
		String path="D:\\apache-tomcat-5.5.17\\webapps\\"+classPath;
		
		return path;
	}
	public static void  main(String arg[]){
		System.out.println(Config.getClassValue("login","sql.properties"));	
	}
}

⌨️ 快捷键说明

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