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();}  
            }  
  • 相关阅读:
    P3688 [ZJOI2017] 树状数组 【二维线段树】
    CF516D Drazil and Morning Exercise【并查集,结论】
    Luogu5540 最小乘积生成树
    CDW数学小笔记
    ZROI 金华集训 线性代数选讲
    多项式乘法(代码)
    我的vimrc
    P4562 [JXOI2018]游戏
    [POJ3585]Accumulation Degree
    [CH5302]金字塔
  • 原文地址:https://www.cnblogs.com/shuaihan/p/8533727.html
Copyright © 2011-2022 走看看