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

📄 configutil.java

📁 博克后台的开发,有很多使用的方法和例子可以提供给大家学习
💻 JAVA
字号:
package com.webpublish.config;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.net.*;

public class ConfigUtil {

	public ConfigUtil() {
	}

	public ConfigUtil(String PropName) {
		this.getConfigFile(PropName);
	}

	private static Properties prop = new Properties();

	private static InetAddress myLocalInfo = null;

	private InetAddress myServer = null;

	public final void getConfigFile(String PropName) {
		try {
			String fileName = "config" + System.getProperty("file.separator")
					+ PropName;
			// System.out.println(fileName);
			prop.load(new FileInputStream(fileName));
		} catch (IOException e) {
			ComStatic.GrainLog.errLog("无法读取配置文件 " + e.toString());
			System.out.println("无法读取配置文件");
		} catch (IllegalArgumentException e) {
			ComStatic.GrainLog.errLog("配置文件包含不符合标准的Unicode escape sequence!");
			System.out.println("配置文件包含不符合标准的Unicode escape sequence!");
		}
	}

	public String getProperty(String name) {
		String value;
		if (prop.containsKey(name)) {
			value = (String) prop.get(name);
		} else {
			value = "";
		}
		return value;
	}

	/*
	 * 取得本地的IP地址信息 HOME/127.0.0.1
	 */
	public static final InetAddress getLocalInfo() {
		try {
			myLocalInfo = InetAddress.getLocalHost();
		} catch (UnknownHostException e) {
			ComStatic.GrainLog.errLog("获得本地IP地址信息是出错!");
			System.out.println("获得本地IP地址信息是出错!");
		}
		return (myLocalInfo);
	}

	/* 
	 * 取得 www.abc.com 的IP地址信息
	 */
	public InetAddress getServerIP(String webUrl) {
		try {
			myServer = InetAddress.getByName(webUrl);
		} catch (UnknownHostException e) {
			ComStatic.GrainLog.errLog("获得网址的IP地址信息是出错!");
			System.out.println("获得网址的IP地址信息是出错!");
		}
		return (myServer);
	}

	public static void main(String[] args) {
		ConfigUtil cu = new ConfigUtil();
		System.out.println(cu.getServerIP("www.sina.com.cn"));
	}
}

⌨️ 快捷键说明

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