import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
public class ConfigureProperties {
private static ConfigureProperties cp = null;
private String MediaServerPath = null;
private String MediaServicePyroProxyIP = null;
private String MediaServicePyroProxyPort = null;
private String propPath = null;
private Properties p = null;
///< 变量 get,set方法
public String getPropPath() {
return propPath;
}
public void setPropPath(String propPath) {
this.propPath = propPath;
}
public String getMediaServerPath() {
return MediaServerPath;
}
public void setMediaServerPath(String mediaServerPath) {
MediaServerPath = mediaServerPath;
}
public String getMediaServicePyroProxyIP() {
return MediaServicePyroProxyIP;
}
public void setMediaServicePyroProxyIP(String mediaServicePyroProxyIP) {
MediaServicePyroProxyIP = mediaServicePyroProxyIP;
}
public String getMediaServicePyroProxyPort() {
return MediaServicePyroProxyPort;
}
public void setMediaServicePyroProxyPort(String mediaServicePyroProxyPort) {
MediaServicePyroProxyPort = mediaServicePyroProxyPort;
}
///< 构造方法
private ConfigureProperties(){
URL basePath = this.getClass().getResource("/");
this.propPath = basePath.getPath() + "configuration.properties";//测试地址
p = new Properties();
try {
FileInputStream fileInputStream = new FileInputStream( new File(this.propPath) );
p.load(fileInputStream);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 读取配置
read();
}
///< 单例
public static ConfigureProperties getInstance(){
if(cp == null)
cp = new ConfigureProperties();
return cp;
}
///< 读取配置
public boolean read(){
this.MediaServerPath = (String)p.get("MediaServerPath");
this.MediaServicePyroProxyIP = (String)p.get("MediaServicePyroProxy.IP");
this.MediaServicePyroProxyPort = (String)p.get("MediaServicePyroProxy.Port");
return true;
}
}
configuration.properties文件的内容为:
# MediaServer configuration
MediaServerPath=http://192.168.5.254/spots/all
MediaServicePyroProxy.IP=192.168.12.85
MediaServicePyroProxy.Port=6000
该配置文件一般放在src文件夹下
需要设置一下:
项目--“右键”点击“属性”--“java构建路径”--“排序和导出”中添加上该文件
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
public class ConfigureProperties {
private static ConfigureProperties cp = null;
private String MediaServerPath = null;
private String MediaServicePyroProxyIP = null;
private String MediaServicePyroProxyPort = null;
private String propPath = null;
private Properties p = null;
///< 变量 get,set方法
public String getPropPath() {
return propPath;
}
public void setPropPath(String propPath) {
this.propPath = propPath;
}
public String getMediaServerPath() {
return MediaServerPath;
}
public void setMediaServerPath(String mediaServerPath) {
MediaServerPath = mediaServerPath;
}
public String getMediaServicePyroProxyIP() {
return MediaServicePyroProxyIP;
}
public void setMediaServicePyroProxyIP(String mediaServicePyroProxyIP) {
MediaServicePyroProxyIP = mediaServicePyroProxyIP;
}
public String getMediaServicePyroProxyPort() {
return MediaServicePyroProxyPort;
}
public void setMediaServicePyroProxyPort(String mediaServicePyroProxyPort) {
MediaServicePyroProxyPort = mediaServicePyroProxyPort;
}
///< 构造方法
private ConfigureProperties(){
URL basePath = this.getClass().getResource("/");
this.propPath = basePath.getPath() + "configuration.properties";//测试地址
p = new Properties();
try {
FileInputStream fileInputStream = new FileInputStream( new File(this.propPath) );
p.load(fileInputStream);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 读取配置
read();
}
///< 单例
public static ConfigureProperties getInstance(){
if(cp == null)
cp = new ConfigureProperties();
return cp;
}
///< 读取配置
public boolean read(){
this.MediaServerPath = (String)p.get("MediaServerPath");
this.MediaServicePyroProxyIP = (String)p.get("MediaServicePyroProxy.IP");
this.MediaServicePyroProxyPort = (String)p.get("MediaServicePyroProxy.Port");
return true;
}
}
configuration.properties文件的内容为:
# MediaServer configuration
MediaServerPath=http://192.168.5.254/spots/all
MediaServicePyroProxy.IP=192.168.12.85
MediaServicePyroProxy.Port=6000
该配置文件一般放在src文件夹下
需要设置一下:
项目--“右键”点击“属性”--“java构建路径”--“排序和导出”中添加上该文件