首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

依据文件名获得properties文件

2012-12-18 
根据文件名获得properties文件直接上代码:package org.commonsimport java.net.URLpublic class Propert

根据文件名获得properties文件
直接上代码:

package org.commons;import java.net.URL;public class PropertiesUtil {/** *  * @param path *            文件名 * @return 该文件的URL */public static URL findAsResource(String path) {URL url = null;// First, try to locate this resource through the current// context classloader.ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();if (contextClassLoader != null) {url = contextClassLoader.getResource(path);}if (url != null)return url;// Next, try to locate this resource through this class's classloaderurl = PropertiesUtil.class.getClassLoader().getResource(path);if (url != null)return url;// Next, try to locate this resource through the system classloaderurl = ClassLoader.getSystemClassLoader().getResource(path);// Anywhere else we should look?return url;}}

热点排行