package ;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import com.chinainsurance.sysframework.exception.BusinessException;
public class PathUtils{
public static String getPath(String pathId){
Properties props = new Properties();
InputStream is =PathUtils.class.getClassLoader().getResourceAsStream("Common.properties");
try {
if(is==null){
throw new Exception("配置文件不存在");
}
props.load(is);
} catch (Exception e) {
e.printStackTrace();
}finally{
if(is != null){
try {
is.close();
} catch (IOException e) {
}
}
}
String vaule =props.getProperty(pathId);
return vaule;
}
/**
* 读取本机IP
* @return
* @throws Exception
*/
public static String getLocalHost() throws Exception {
Properties prop = new Properties();
String localHost = "";
InputStream in = null;
try{
//读取属性文件nativeIp.properties
in = new BufferedInputStream (new FileInputStream(System.getProperty("user.dir")+"/businessConfig/system.properties"));
prop.load(in); ///加载属性列表
localHost = prop.getProperty("nativeip");
in.close();
}catch(Exception e){
e.printStackTrace();
throw new BusinessException("读取本地IP异常,请处理!",null);
}finally{
in.close();
}
return localHost;
}
public static void main(String[] args) {
System.out.println(PathUtils.getPath("app1"));
}
}