Propertiesコレクション_Listメソッドとstoreメソッド
3358 ワード
Propertiesコレクションとストリームオブジェクトを組み合わせた機能
List()メソッド:
store()メソッド:
List()メソッド:
import java.util.Properties;
public class PropertiesDemo {
public static void main(String[] args) {
propertiesDemo();
}
public static void propertiesDemo() {
Properties prop = new Properties();
prop.setProperty("02", "huangjianfeng");
prop.setProperty("03", "jianfeng");
prop.setProperty("04", "feng");
prop.list(System.out);// ,
}
}
store()メソッド:
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class PropertiesDemo {
public static void main(String[] args) throws IOException {
propertiesDemo();
}
public static void propertiesDemo() throws IOException {
Properties prop = new Properties();
prop.setProperty("02", "hujianfeng");
prop.setProperty("03", "jianfeng");
prop.setProperty("04", "feng");
// ,
FileOutputStream fos = new FileOutputStream("F:\\info.txt");
// , store
prop.store(fos, "number+name");// ,
fos.close();
}
}