文件IO-Properties
生活随笔
收集整理的這篇文章主要介紹了
文件IO-Properties
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
java.lang.Object
繼承者 java.util.Dictionary<K,V>
繼承者 java.util.Hashtable<Object,Object>
繼承者 java.util.Properties
所有已實(shí)現(xiàn)的接口:
Serializable, Cloneable, Map<Object,Object>
1.構(gòu)造方法
Properties();Properties(Properties default):創(chuàng)建一個(gè)帶有默認(rèn)值的空屬性列表2.主要方法:
getProperty(String key)通過(guò)指定的鍵獲取屬性,返回的是一個(gè)字符串load(InputStream inStream)從輸入流中讀取屬性列表load(Reader reader)按簡(jiǎn)單的面向行的格式從輸入字符流中讀取屬性列表setProperty(String key,String value),向列表中輸入鍵值對(duì)store(OutputStream os,String commit)將此 Properties 表中的屬性列表(鍵和元素對(duì))寫(xiě)入輸出流,commit為注釋store(Writer writer,String commit)將此 Properties 表中的屬性列表(鍵和元素對(duì))寫(xiě)入輸出字符stringPropertyNames();返回一個(gè)set集合的鍵值對(duì)字符串 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();} }總結(jié)
以上是生活随笔為你收集整理的文件IO-Properties的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 文件IO流
- 下一篇: Struts2-Action的基本流程