public void setProperties(String property_file) {
Properties props = new Properties(System.getProperties());
try {
props.load(new BufferedInputStream(new FileInputStream(property_file)));
System.setProperties(props);
} catch (FileNotFoundException fne) {
System.err.println("找不到文件:" + fne);
} catch (Exception e) {
……
}
}以后就使用System.getProperty(String)
Properties props = new Properties(System.getProperties());
try {
props.load(new BufferedInputStream(new FileInputStream(property_file)));
System.setProperties(props);
} catch (FileNotFoundException fne) {
System.err.println("找不到文件:" + fne);
} catch (Exception e) {
……
}
}以后就使用System.getProperty(String)
解决方案 »
- 广播编程的问题,我的接收端无法接收发送端发来的数据
- jsdk里有没有将int数高低位交换的函数?
- 重金悬赏100分求程序代码(文本文件中的单词统计)
- Can recommend a better java compression library?
- 高手进来给点意见吧,关于JAVA做EMAIL Client
- 从一数据连接池获得的Connection不能setAutoCommit()吗?
- 简单的不得了的问题!在线解决,马上送分!
- javamail问题,如果哪位老大帮忙解决了,一定酬谢!!
- 帮忙啊!!!!!来者又分
- 请问Properties 的void store(OutputStream out,String header)怎么用?
- swing的问题还是jbuiler的问题??
- 如何将ASCII码转换为8859-1的编码的String 急急
先把这些路径写在配置文件中XXX.properties文件中,如何写一个类进行实际与虚拟路径的转换。
配制文件为:
reportpath=D:/WebSphere/AppServer/installedApps/GMIMS.ear.ear/gmims.war/report/
reporturl=/report/转换的类为: public Config()
{
reportPath = "c:/";
reportURL = "http://localhost/report/";
FileInputStream fio = null;
Properties proInfo = new Properties(); try
{
fio = new FileInputStream("c:\\XXX.properties");
}
catch(FileNotFoundException ex)
{
System.out.println("FileNotFoundException While Open File:" + ex.toString());
}
catch(SecurityException ex)
{
System.out.println("SecurityException While Open File:" + ex.toString());
}
catch(Exception ex)
{
System.out.println("Exception While Open File:" + ex.toString());
}
try
{
proInfo.load(fio);
}
catch(IOException ex)
{
System.out.println("IOException While Load Info:" + ex.toString());
}
try
{
fio.close();
}catch(Exception ex)
{
System.out.println("IOException While Close File:" + ex.toString());
}setReportPath(proInfo.getProperty("reportpath", "c:/"));
setReportURL(proInfo.getProperty("reporturl", "http://localhost/myapp/report/"));
}public String getReportPath()
{
return reportPath;
} public String getReportURL()
{
return reportURL;
}
private void setReportPath(String newReportPath)
{
reportPath = newReportPath;
} private void setReportURL(String newReportURL)
{
reportURL = newReportURL;
}
}希望能给点帮助!
在shell脚本里 cat $MY_HOME > pathfile
然后从pathfile 读取
Dos 当然不能用cat了,可以用type,呵呵。