• 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();}  
            }  
  • 相关阅读:
    Hamming Distance(随机算法)
    Difference Between Primes
    Pet(dfs)
    29. Divide Two Integers
    28. Implement strStr()
    25. Reverse Nodes in k-Group
    24. Swap Nodes in Pairs
    23. Merge k Sorted Lists
    22. Generate Parentheses
    19. Remove Nth Node From End of List
  • 原文地址:https://www.cnblogs.com/shuaihan/p/8533727.html
Copyright © 2020-2023  润新知