文件IO-Properties
生活随笔
收集整理的這篇文章主要介紹了
文件IO-Properties
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
java.lang.Object
繼承者 java.util.Dictionary<K,V>
繼承者 java.util.Hashtable<Object,Object>
繼承者 java.util.Properties
所有已實現(xiàn)的接口:
Serializable, Cloneable, Map<Object,Object>
1.構造方法
Properties();Properties(Properties default):創(chuàng)建一個帶有默認值的空屬性列表2.主要方法:
getProperty(String key)通過指定的鍵獲取屬性,返回的是一個字符串load(InputStream inStream)從輸入流中讀取屬性列表load(Reader reader)按簡單的面向行的格式從輸入字符流中讀取屬性列表setProperty(String key,String value),向列表中輸入鍵值對store(OutputStream os,String commit)將此 Properties 表中的屬性列表(鍵和元素對)寫入輸出流,commit為注釋store(Writer writer,String commit)將此 Properties 表中的屬性列表(鍵和元素對)寫入輸出字符stringPropertyNames();返回一個set集合的鍵值對字符串 public class Demo09 {public static void main(String[] args) {Properties properties = new Properties();properties.setProperty("zsh", "1");properties.setProperty("zms","2");properties.setProperty("sks","3");Set<String> strings = properties.stringPropertyNames();for(String key:strings){String value = properties.getProperty(key);System.out.println(key+"="+value);}} import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Properties;public class Demo10 {public static void main(String[] args) throws IOException {Properties properties = new Properties();properties.setProperty("sks","180");properties.setProperty("zsh","170");FileWriter fileWriter = new FileWriter("G:" + File.separator + "demo.txt");properties.store(fileWriter,"sava data");fileWriter.close();} }總結
以上是生活随笔為你收集整理的文件IO-Properties的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 文件IO流
- 下一篇: Struts2-Action的基本流程