zoukankan      html  css  js  c++  java
  • java 操作Properties文件

    package cn.studio.util;

    import java.io.*;
    import java.net.URISyntaxException;
    import java.net.URL;

    import java.util.Properties;

    public class Properties_Utils {

     public static Properties props;
     public static InputStream in;
     public static OutputStream out;

     static {
      try {
       URL url = Properties_Utils.class.getClassLoader().getResource(
         "time.properties");

       File file;
       file = new File(url.toURI());

       out = new FileOutputStream(file);
       props = new Properties();
       in = Properties_Utils.class.getResourceAsStream("/user.properties");
       props.load(in);
      } catch (FileNotFoundException e1) {
       e1.printStackTrace();
      } catch (URISyntaxException e1) {
       e1.printStackTrace();
      } catch (IOException e) {
       e.printStackTrace();
      }
     }

     // 根据key读取value
     public static String readValue(String key) {
      String value = props.getProperty(key);
      return value;

     }

     // 根据key增加值value
     public static String writeValue(String key, String value) {
      props.setProperty(key, value);
      return value;
     }

     public static void addProperty(String key, String value) {

      props.setProperty(key, value);

      try {
       props.store(out, null);
      } catch (IOException e) {
       e.printStackTrace();
      }

     }

     // 查找某个值是否在key中
     public static boolean isInKey(String key, String value) {
      System.out.println(readValue(key));
      String[] values = readValue(key).split(",");
      for (String v : values) {
       if (v.equals(value)) {
        return true;
       }
      }
      return false;
     }

    }

  • 相关阅读:
    私活。
    sql server 模拟数组【转】
    Updlock 与 Holdlock
    连上交换机后电脑无法上网
    linux的发展
    MySQL5.7中,用root用户登陆不进去数据库,报以下错误,然后重新修改了密码,好了。
    nginx反响代理tomcat配置ssl
    tomcat日志的切割脚本
    重启nginx报错:[error] invalid PID number "" in "/application/nginx-1.13.3/logs/nginx.pid"
    数据盘的挂载
  • 原文地址:https://www.cnblogs.com/33blog/p/2610780.html
Copyright © 2011-2022 走看看