Properties properties = new Properties();
FileInputStream fis = new FileInputStream("huhx.properties");
properties.load(fis);
System.out.println(properties.get("name"));
PrintStream printStream = System.out; properties.list(printStream);
public void list(PrintStream out) {
out.println("-- listing properties --");
Hashtable h = new Hashtable();
enumerate(h);
for (Enumeration e = h.keys() ; e.hasMoreElements() ;) {
String key = (String)e.nextElement();
String val = (String)h.get(key);
if (val.length() > 40) {
val = val.substring(0, 37) + "...";
}
out.println(key + "=" + val);
}
}
OutputStream outputStream = new FileOutputStream("huhx.txt");
properties.store(outputStream, "comments");
OutputStream outputStream2 = new FileOutputStream("huhx.xml");
properties.storeToXML(outputStream2, "comments");
#comments #Thu May 19 19:19:36 CST 2016 name=huhx
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>comments</comment> <entry key="name">huhx</entry> </properties>
package com.huhx.linux;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Properties;
public class PropertiesTest {
public static void main(String[] args) throws Exception {
// 一般Properties的使用
Properties properties = new Properties();
FileInputStream fis = new FileInputStream("huhx.properties");
properties.load(fis);
System.out.println(properties.get("name"));
// 以下是测试的部分
PrintStream printStream = System.out;
properties.list(printStream);
OutputStream outputStream = new FileOutputStream("huhx.txt");
properties.store(outputStream, "comments");
OutputStream outputStream2 = new FileOutputStream("huhx.xml");
properties.storeToXML(outputStream2, "comments");
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有