zoukankan      html  css  js  c++  java
  • Properties工具类


    /*
    * Author: frank
    * Properties工具类
    */
    package com.he;


    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.Writer;
    import java.util.Properties;

    public class PropertiesTool {
        private static Properties prop = null;
        private static final String path = "src/test.properties" ;
            
        private static void init() {
            prop = new Properties();
            InputStream is = null;
            try {
                is = PropertiesTool.class.getClassLoader().getResourceAsStream("test.properties");
                prop.load(is);
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            
        }
        
        public static String getProperty(String key) {
            
            if(prop == null) {
                init();
            }
            return prop.getProperty(key);
        }
        
         public static boolean setProperties(String key,String value) {  
               
               if(prop == null) {
                    init();
                }

                Writer writer = null;
                try {
                    writer = new FileWriter(path);
                    prop.setProperty(key, value);
                    prop.store(writer, key);  
                    
                    return true;
                } catch (IOException e) {
                    e.printStackTrace();
                    return false;
                } finally {
                    try {
                        if(writer != null) {
                            writer.close();
                        }
                    } catch(Exception e) {
                        e.printStackTrace();
                    }
                    
                }
         }  
    }

  • 相关阅读:
    五种提高 SQL 性能的方法
    join 使用详解方式
    关于MagicAjax的用法
    收藏几段SQL Server语句和存储过程
    ubuntu nfs配置 以及mount.nfs:access denied by server while mounting问题解决
    Hisi开发板上 SQLite3.3.8移植
    父进程非阻塞回收子进程(适用LINUX下C语言的clientserver模型)
    busybox asm/page.h: No such find.
    ubuntu11.10 samba服务器配置
    errno定义
  • 原文地址:https://www.cnblogs.com/hzm112567/p/2838426.html
Copyright © 2011-2022 走看看