在代码中读取MAXIMO的安装路径, 同时读取properties文件
2012-01-06 11:32
513 查看
昨天在一个项目中,需要额外读取一个properties文件,properties文件存放在maximo/properties文件夹下。首先这就要读取到maximo的安装路径,当然这也是最关键的一步。
多谢 Fedora Maximo(438658902) 提供的hello.class.getProtectionDomain().getCodeSource().getLocation().getFile()方法。呵呵,现在把测试代码贴出来:
在探索的过程中发现了maximo自带一个读取配置文件的方法:
多谢 Fedora Maximo(438658902) 提供的hello.class.getProtectionDomain().getCodeSource().getLocation().getFile()方法。呵呵,现在把测试代码贴出来:
String locTemp = CuMRActionAPPR2YG.class.getProtectionDomain().getCodeSource().getLocation().getFile(); String maximoAddress = locTemp.substring(1, locTemp.lastIndexOf("maximo")); Properties prop = new Properties(); InputStream in = null; try { in = new BufferedInputStream(new FileInputStream(maximoAddress+"properties/ygjk.properties")); prop.load(in); fmisAddress = prop.getProperty("fmis.address.ip").trim(); System.out.println("fmisAddress:>>>"+fmisAddress); } catch (FileNotFoundException e1) { e1.printStackTrace(); throw new MXApplicationException("提示 #", "配置文件不存在,请与管理员联系。"); } catch (IOException e) { e.printStackTrace(); throw new MXApplicationException("提示 #", "读取配置文件错误,,请与管理员联系。"); } finally { if(in != null){ try { in.close(); } catch (IOException e) { e.printStackTrace(); } } }
在探索的过程中发现了maximo自带一个读取配置文件的方法:
String tempPro = MXServer.getMXServer().getProperty("fmis.address.ip"); System.out.println(">>>>>>>>>"+tempPro);但是貌似这个方法只能读取maximo自带的那个maximo.properties中的配置。自己加上去的key-value 读取不到,这个有时间再探索下。。。
相关文章推荐
- 读取配置参数的properties文件,路径获取完美解决
- java代码读取properties文件
- java定时框架Quartz的简单应用(附:读取properties文件参数代码)
- java读取properties报文件找不到路径
- Java项目中读取properties文件,以及六种获取路径的方法
- JAVA读取properties文件代码 单例模式
- java读取properties文件,获取路径的方法
- java读取项目根路径下和任意磁盘位置下的properties文件
- 读取配置参数的properties文件,路径获取完美解决
- java web中读取properties文件时的路径问题
- RCP中Properties文件路径和内容读取
- 读取属性文件config.properties中的上传文件路径
- 关于读取Properties文件的相对路径问题,怎么写是正确的?
- 读取web项目properties文件路径 解决tomcat服务器找不到properties路径问题
- properties文件路径的读取
- 一句代码读取properties文件内容
- jsp中写java代码读取放在src下的XX.properties文件的程序
- java读取properties文件的简单代码
- ResourceBundle读取properties文件 代码片段
- java处理国际化和读取properties文件代码片段