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();
                    }
                    
                }
         }  
    }

  • 相关阅读:
    将某个MySQL库中的UTF8字符列都转成GBK格式
    挺苹果的声音,iPhone 5s的两处进步
    Cookie 路径在本机测试及服务器部署,在浏览器处理方式上的不同
    inner join、left join、right join中where和and的作用
    TIA Portal V12不能添加新的CPU
    Linux下可执行程序调试信息的分离及release程序的调试
    STM32.定时器
    STM32.SPI(25Q16)
    模电之运放篇
    Zigbee学习
  • 原文地址:https://www.cnblogs.com/hzm112567/p/2838426.html
Copyright © 2011-2022 走看看