方法1
public class Hello {
//读取配置文件信息
private static InputStream inputStream = null;
private static Properties properties = null;
private static String server;
private static String code;
private static String address;
private static String protocol;
static {
try{
properties = new Properties();
inputStream = Thread.class.getResourceAsStream("/user.properties");
properties.load(inputStream);
server = properties.getProperty("server");
code = properties.getProperty("code");
protocol = properties.getProperty("protocol");
address = properties.getProperty("address");
}catch (Exception e) {
e.printStackTrace();
}finally {
if(inputStream != null){
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
方法2

网友评论