侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Properties 模块读取配置文件

2023-11-09 星期四 / 0 评论 / 0 点赞 / 39 阅读 / 1652 字

package TestDemo; import java.io.IOException; import java.io.InputStream; import java.sql.Connection

package TestDemo;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;

public class Test_0523 {
    private  String hostname = "127.0.0.1";
    public void getConnection (){
    Properties pr = new Properties();
    InputStream in = Test_0523.class.getClassLoader().getResourceAsStream( "TestDemo/jdbc.properties");
    try {
        pr.load(in);
        String url = pr.getProperty("url");
        System.out.println(url);
        String hosts = pr.getProperty("hosts");
    String [] hostss = hosts.split(" ");
    for (String i : hostss) {
        System.out.println("ping" +" "+ i);
    }
        
    } catch (IOException e) {
        // TODO 自动生成的 catch 块
        e.printStackTrace();
    }
    }
    
    public static void main (String []args){
        Test_0523 ts = new Test_0523();
        ts.getConnection();    
        
    }
}
 

广告 广告

评论区