package com.test.javaSe01;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class PropertiesTestDemo {
public static void main(String[] args) {
Properties pro = new Properties();
pro.setProperty("driver", "com.mysql.jdbc.Driver");
pro.setProperty("url",
"jdbc:mysql://localhost:3306/netctoss?unicode=true&characterEncoding=utf8");
pro.setProperty("username", "root");
pro.setProperty("password", "admin");
System.out.println(pro);
File file = new File("H:" + File.separator + "ctl/lin" + File.separator
+ "mysql.properties");
if(!file.exists()){
try {
new File(file.getParent()).mkdirs();
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
pro.store(new FileOutputStream(file), "mysql链接");
} catch (Exception e) {
System.err.println("存储properties出错");
}
}
}
存储properties资源文件
最新推荐文章于 2023-08-17 14:19:38 发布