package com.liberay.tool.utils; import java.io.IOException; import java.io.InputStream; import java.util.Properties; /** * @author Administrator * 读取同目录下的properties文件,并可以根据key值获取对应的value值得 */ public final class FileProperties { private static String defaultFile = "property.properties"; private static Properties properties = new Properties(); static{ try { InputStream stream = FileProperties.class.getResourceAsStream(defaultFile); properties.load(stream); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private static Properties readFile(String fileName){ try { InputStream stream = FileProperties.class.getResourceAsStream(fileName); properties.load(stream); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return properties; } public static String getProperty(String key){ return properties.getProperty(key); } public static String getProperty(String key,String fileName){ properties = readFile(fileName); return getProperty(key); } } 关于资源的利用是不是还可以调整一下!功能是实现了,但是我从来不思考性能!哪位大虾可以帮忙处理下。