欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

properties小案例 博客分类: java  

程序员文章站 2024-03-22 10:16:10
...
package com.my.properties;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class TestProperties {

public static void main(String[] args) {
InputStream inputStream=null;
Properties p=null;
try {
inputStream = new FileInputStream(new File("jdbc.properties"));
        p = new Properties(); 
        p.load(inputStream); 
        inputStream.close(); 
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
} finally{
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(
"driverClassName:"+p.getProperty("driverClassName")+"\n"
+"url:"+p.getProperty("url")+"\n"
+"username:"+p.getProperty("username")+"\n"
+"password:"+p.getProperty("password")+"\n"
+"maxActive:"+p.getProperty("maxActive")+"\n"
+"maxIdle:"+p.getProperty("maxIdle")+"\n"
+"minIdle:"+p.getProperty("minIdle")+"\n"
+"initialSize:"+p.getProperty("initialSize")); 
   
}
}

以上代码复制可用