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

  • 相关阅读:
    小程序双重for循环实现tab切换小demo
    小程序基础操作小总结
    一道关于类型转换的面试题的研究
    面试准备(6)vue专题
    面试准备(5)一道关于循环,事件执行顺序的题进行剖析
    微信小程序弹出授权用户信息和手机号
    面试准备(4) 作用域 预解析 字面量 arguments 等考察点练习
    ABC135
    CodeForces 1288C
    P4170
  • 原文地址:https://www.cnblogs.com/xumin/p/3143762.html
Copyright © 2020-2023  润新知