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 上手指南
    简单聊聊 Ironic
    什么是裸金属
    使用 minikube 快速上手 Kubernetes | v1.7.3
    来看看你对Python变量理解到位了没有
    python HelloWorld 的 4 种姿势,你知道几种
    Windows 系统安装 Python 3.8 详解
    myeclipse2017下载安装与破解详细教程
    eclipse中tomcat的add and Remove找不到项目
    cmd中查看MySQL数据库表数据及结构
  • 原文地址:https://www.cnblogs.com/xumin/p/3143762.html
Copyright © 2011-2022 走看看