代码如下:
package com.test;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
public class ConProperty {
private Properties pro;
private InputStreamReader instream;
public void init() throws IOException,FileNotFoundException{
pro=new Properties();
instream=new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("conf.properties"),"UTF-8");
if(instream !=null){
pro.load(instream);
}else{
throw new FileNotFoundException("property file not found in the classpath");
}
}
public String getfirefox(){
return pro.getProperty("firefox");
}
public String getsqlIP(){
return pro.getProperty("sqlIP");
}
public String getdbname(){
return pro.getProperty("dbname");
}
public String getsqluser(){
return pro.getProperty("sqluser");
}
public String getsqlpass(){
return pro.getProperty("sqlpass");
}
public String getresolutionPath(){
return pro.getProperty("resolutionPath");
}
public String getdownloadsAbsoluteLocat(){
return pro.getProperty("downloadsAbsoluteLocat");
}
public static void main(String[] args) {
ConProperty conProperty=new ConProperty();
try {
conProperty.init();
System.out.println(conProperty.getdownloadsAbsoluteLocat());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}