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;
	}
}

你可能感兴趣的:(java,xml)