zoukankan      html  css  js  c++  java
  • JAVA读取properties

     InputStream is=null;  
            OutputStream os=null;
            
            Properties props = new Properties();  
            InputStream in = null;  
            
            //读取properties
            try {  
                //第一种,通过类加载器进行获取properties文件流  
                //in = PropertyUtil.class.getClassLoader().getResourceAsStream("sysConfig.properties");  
                //第二种,通过类进行获取properties文件流  
                in = CardUtil.class.getResourceAsStream("/card.properties");  
                props.load(in);  
                props.getProperty("key");
            } catch (FileNotFoundException e) {  
                //logger.error("sysConfig.properties文件未找到"); 
                e.printStackTrace();
            } catch (IOException e) {  
                //logger.error("出现IOException");
                e.printStackTrace();
            } finally {  
                try {  
                    if(null != in) {  
                        in.close();  
                    }  
                } catch (IOException e) {  
                    //logger.error("sysConfig.properties文件流关闭出现异常");  
                    e.printStackTrace();
                }  
            }  
           
            String urlAll=null;
            String NewmyFileFileName=null;
            try {  
                is = new BufferedInputStream(new FileInputStream(myFile)); 
                String uuid = UUID.randomUUID().toString().replaceAll("-", "");
                NewmyFileFileName=uuid+myFileFileName.substring(myFileFileName.lastIndexOf("."));
                urlAll=props.getProperty("toPath")+NewmyFileFileName;
                os = new BufferedOutputStream(new FileOutputStream(urlAll));  
                  
                byte[] buffer = new byte[1024];  
                int len=0;  
                while((len=is.read(buffer))>0){  
                    os.write(buffer,0,len);  
                }     
            }finally{  
                if(is !=null){is.close();}  
                if(os!=null){os.close();}  
            }  
  • 相关阅读:
    实验4:开源控制器实践——OpenDaylight
    实验3:OpenFlow协议分析实践
    SDN实验2:Open vSwitch虚拟交换机实践
    实验1:SDN拓扑实践
    面向对象程序设计2020寒假作业3
    自我介绍
    Python进程和线程
    同步 Github fork 出来的分支
    Git指令中fetch和pull的区别
    Git多人协作维护仓库简单流程
  • 原文地址:https://www.cnblogs.com/shuaihan/p/8533727.html
Copyright © 2011-2022 走看看