Java reads key-value pairs in configuration files, tool classes

public class T {
    
    
    public static String Properties(String key,String propertiespath){
    
    
    String str="";
        Properties properties = new Properties();
        FileInputStream  in = null;
        try {
    
    
            in= new FileInputStream(propertiespath);
            properties.load(in); //从配置文件中获取键值对

   str=properties.getProperty(key);
   
   in.close();
        } catch (FileNotFoundException e) {
    
    
            e.printStackTrace();
        } catch (IOException e) {
    
    
            e.printStackTrace();
        }
        return str;
    }

public static String Properties(String key,InputStream in){
    
    
   		String str="";    
        Properties properties = new Properties();  
         try {
    
            
         properties.load(in); //从配置文件中获取键值对  
          str=properties.getProperty(key);                     
          in.close();  
          } catch (FileNotFoundException e) {
    
                       
             e.printStackTrace();   
         } catch (IOException e) {
    
            
       		 e.printStackTrace();    
        }       
         return str;  
      }
}       

application.properties file content:

path = c://upload//

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324352203&siteId=291194637