读取resource下的test.properties文件,代码如下
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertiesUtil {
public String getValue(String name){
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("test.properties");
Properties properties = new Properties();
try{
properties.load(inputStream);
}catch (IOException ioE){
ioE.printStackTrace();
}finally{
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(name+":"+properties.getProperty(name));
return properties.getProperty(name);
}
}