import java.io.FileOutputStream;
import java.util.Properties;
public class TestProperties {
public static void main(String[] args) {
Properties properties = new Properties();
properties.put("dbtype", "oracle912");
properties.put("language", "chinese");
try{
properties.store(new FileOutputStream("f://properties.txt"), "001");
}catch(Exception e){
e.printStackTrace();
}
String dbtype = "";
String language = "";
dbtype = properties.getProperty("dbtype");
language = properties.getProperty("language");
System.out.println(dbtype + " " + language);
}
}
f://properties.txt文件内容如下:
dbtype=oracledb
language=English
本文提供了一个使用 Java 的 Properties 类来读写配置文件的例子。演示了如何创建 Properties 对象、添加键值对并将其保存到文件中,同时展示了如何从文件加载属性。
412

被折叠的 条评论
为什么被折叠?



