📄 readproperty.java
字号:
package com.zzrd.j60.p100.common;
import java.io.FileInputStream;
import java.util.Properties;
/**
* 功能介绍<br>
* ReadProperty生成<br>
*
*
*/
public class ReadProperty{
/* 声明变量*/
private static FileInputStream is = null;
private static Properties props;
/**
* 取得String值 <br>
* @return String值 <br>
* @param sPropName <br>
* @param[sPropName] <br>
* @exception[Exception] <br>
*/
public static String getString(String sPropName) throws Exception{
String sPropValue = String.valueOf(-1);
open();
sPropValue = props.getProperty(sPropName);
close();
return sPropValue;
}
/**
* 取得int值
* @return int值
* @params PropName
* @param[sPropName]
* @exception[Exception]
*/
public static int getInt(String sPropName) throws Exception{
int nPropValue = -1;
open();
nPropValue = Integer.parseInt(props.getProperty(sPropName));
close();
return nPropValue;
}
/**
* 打开property file
* @return[无]
* @param[无]
* @param[无]
* @exception[Exception]
*/
private static synchronized void open() throws Exception{
props = new Properties();
ReadProperty rp = new ReadProperty();
String path = rp.findPath();
is = new FileInputStream(path);
props.load(is);
}
/**
* 关闭property file
* @return[无]
* @param[无]
* @param[无]
* @exception[Exception]
*/
private static void close() throws Exception{
is.close();
}
/**
* 取得property file的路径
* @return property file 路径
*/
private String findPath() throws Exception{
String path = this.getClass().getClassLoader().getResource("").getPath();
int pathLength = path.length();
path = path.substring(1,pathLength - 8);
path = path + "lib/Resource.properties";
return path;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -