`

利用java.util.Properties从properties文件读入properties

阅读更多
java 代码
 
  1. // reads the properties from the property file  
  2.        Properties props = new Properties();  
  3.        try {  
  4.            props.load(new FileInputStream(PROPERTIES_FILE));  
  5.        } catch (IOException ex) {  
  6.            System.out.println("error configuring unit tests");  
  7.            ex.printStackTrace();  
  8.        }  
  9.   
  10.        SFTP_HOSTNAME = props.getProperty("server");  
  11.        InetAddress temp = null;  
  12.        try {  
  13.            temp = InetAddress.getByName(SFTP_HOSTNAME);  
  14.        } catch (UnknownHostException ex) {  
  15.            System.out.println("error resolving host " + SFTP_HOSTNAME);  
  16.        }  
  17.        SFTP_HOST = temp;  
  18.   
  19.        USERNAME = props.getProperty("username");  
  20.        PASSWORD = props.getProperty("password");  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics