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"));
}
}
以上代码复制可用
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"));
}
}
以上代码复制可用
推荐阅读
-
第二届战神杯线上编程挑战赛月赛第一题:回文数 博客分类: java java编程
-
properties小案例 博客分类: java
-
JAVA生成缩略图 博客分类: java
-
The 3n + 1 problem 博客分类: java
-
回文距离 博客分类: java java
-
Java多线程 博客分类: 多线程
-
java反射强制赋值 博客分类: java
-
SpringMVC中JSP取不到ModelAndView的数据的原因 博客分类: java Java spring springMVC
-
JDK代理模式 博客分类: java
-
第五届在线编程大赛月赛第一题:完全平方数的个数 博客分类: java java