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

  • 相关阅读:
    Ubuntu16.04下搭建LAMP环境
    关于下载SAE日志签名认证的方法——PHP版
    时隔这么长时间,又回来写博客了
    转战网站后台与python
    学习之路
    周末随笔
    Shell基础-环境变量配置文件
    关于骑行
    MYSQL 8.0 linux安装步骤
    一个golang项目笔记 (二) 动态加载库
  • 原文地址:https://www.cnblogs.com/xumin/p/3143762.html
Copyright © 2011-2022 走看看