`
zeyuphoenix
  • 浏览: 56028 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

XML简单读取

阅读更多
/**
 * LoadXMl.java
 * @author <br>
 *         2007/11/09 13:49:35
 */
public class LoadXMl {
	/**
	 * LoadXMl
	 */
	public LoadXMl() {

	}

	/**
	 * LoadXMl
	 * @param fullPath
	 * @return Properties
	 * @throws Exception
	 */
	public static Properties loadProperties(String fullPath) throws Exception {
		Properties properties = new Properties();
		InputStream is = null;

		try {
			URL url = getResourceURL(fullPath);
			is = url.openStream();
			properties.loadFromXML(is);
		} catch (Exception ex) {

			Exception sex = new Exception("configFileName [" + fullPath + "]  Load Error", ex);
			throw sex;
		} finally {
			try {
				is.close();
			} catch (Exception ignore) {
			}
		}
		return properties;
	}

	/**
	 * get path url
	 * @param path
	 *        config path
	 * @return path url
	 */
	private static URL getResourceURL(String path) throws MalformedURLException {
		URL url = null;

		try {
			// get path url
			url = (new File(path)).toURI().toURL();

		} catch (MalformedURLException e) {
			throw e;
		}
		return url;
	}
}
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

Global site tag (gtag.js) - Google Analytics