首页 > 代码库 > 读取.properties配置文件

读取.properties配置文件

文件内容:

url=jdbc:oracle:thin:@192.168.1.222:1521:orcl
userName=dwp
passWord=ghc_211
driverName=oracle.jdbc.driver.OracleDriver

 

package util;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.util.Properties;import java.util.regex.Matcher;import java.util.regex.Pattern;import org.apache.poi.hssf.usermodel.HSSFCell;import org.apache.poi.hssf.usermodel.HSSFCellStyle;import org.apache.poi.hssf.usermodel.HSSFFont;import org.apache.poi.hssf.usermodel.HSSFRow;import org.apache.poi.hssf.usermodel.HSSFSheet;import org.apache.poi.hssf.usermodel.HSSFWorkbook;import org.apache.poi.hssf.util.HSSFColor;public class Test{    public static void main (String[] args) throws IOException{        Properties pro = new Properties();        FileInputStream in =null;        try{            in = new FileInputStream("config\\db.properties");        }catch (FileNotFoundException e){            // TODO Auto-generated catch block            e.printStackTrace();        }        pro.load(in);        System.out.println (pro.getProperty ("driverName"));        //           }}

  

读取.properties配置文件