[Java] 文件操作--读写Properties文件 →→→→→进入此内容的聊天室

来自 , 2020-04-15, 写在 Java, 查看 143 次.
URL http://www.code666.cn/view/819c9fbf
  1. package My;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.util.ArrayList;
  7. import java.util.HashMap;
  8. import java.util.Properties;
  9.  
  10. public class PropertiesUtils
  11. {
  12.         static String proPath = "src/my/conf.properties";
  13.         static Properties pro = null;
  14.         static ArrayList<String> list = new ArrayList<String>();
  15.         HashMap<String, String> map = new HashMap();
  16.  
  17.         static public void ReadProperties()
  18.         {
  19.                 pro = new Properties();
  20.                 FileInputStream in;
  21.                 try
  22.                 {
  23.                         in = new FileInputStream(proPath);
  24.                         pro.load(in);
  25.                         in.close();
  26.                 }
  27.                 catch (IOException e)
  28.                 {
  29.                         e.printStackTrace();
  30.                 }
  31.         }
  32.  
  33.         static public void WriteProperties(String key, String value)
  34.         {
  35.                 try
  36.                 {
  37.                         FileOutputStream oFile = new FileOutputStream(proPath, false);// true表示追加打开
  38.                         pro.setProperty(key, value);
  39.                         pro.store(oFile, "test");
  40.                         oFile.close();
  41.                 }
  42.                 catch (IOException e)
  43.                 {
  44.                         e.printStackTrace();
  45.                 }
  46.  
  47.         }
  48.  
  49.         public static void main(String[] args)
  50.         {
  51.                 ReadProperties();
  52.                 WriteProperties("城市", "洛阳");
  53.         }
  54. }
  55.  

回复 "文件操作--读写Properties文件"

这儿你可以回复上面这条便签

captcha