zoukankan      html  css  js  c++  java
  • 读propert文件

    PropertiesUtil.java

    package utils;
    
    import java.io.BufferedInputStream;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Properties;
    
    public class PropertiesUtil {
        private static InputStream in;//=prop.class.getClassLoader().getResourceAsStream("resource/date.properties");
        private static Properties props;
        private static String filePath=PropertiesUtil.class.getClassLoader().getResource("resource/date.properties").getFile();//.getPath();
        static{
            props=new Properties();
            
                try {
                    in=new BufferedInputStream(new FileInputStream(filePath));
                    props.load(in);
                } catch (FileNotFoundException e1) {
                    e1.printStackTrace();
                }catch (IOException e) {
                    e.printStackTrace();
                }
        }
        public static String readStringValue(String key) {
            return props.getProperty(key);
        }
        
        public static int readIntValue(String key) {
            return Integer.valueOf(props.getProperty(key));
        }
        
        public static Float readFloatValue(String key) {
            return Float.valueOf(props.getProperty(key));
        }
        
        public static String[] readStringArray(String key,String regex) {
            return props.getProperty(key).split(regex);
        }
        
        /**
         * @param args
         */
        public static void main(String[] args) {
            System.out.println(PropertiesUtil.readStringValue("aa"));
            System.out.println(PropertiesUtil.readIntValue("age"));
            System.out.println(PropertiesUtil.readFloatValue("fl"));
            System.out.println(PropertiesUtil.readStringArray("aa",",")[1]);
        }
    
    }

    date.properties

    #用来测试的
    aa=1,2,3,4,54,54,5,43,5,32,3,4532,45
    age=1
    fl=1.1

      public static boolean isNumeric(String str){
            Pattern pattern = Pattern.compile("[0-9]*");
            return pattern.matcher(str).matches();   
         }

    String.format("%03d",Integer.valueOf(no2)+1);

  • 相关阅读:
    使用vagrant一键部署本地php开发环境(一)
    产品化机器学习的一些思考
    突破、进化,腾讯云数据库2018全年盘点
    WebGL 纹理颜色原理
    如何定制Linux外围文件系统?
    一文了解腾讯云数据库SaaS服务
    如何正确的选择云数据库?
    Node.js 进程平滑离场剖析
    Git合并不同url的项目
    mariadb 内存占用优化
  • 原文地址:https://www.cnblogs.com/xumin/p/3143762.html
Copyright © 2011-2022 走看看