2017-07-31 41 views

回答

0

我不知道你嘗試了什麼,並從你嘗試讀取屬性文件的位置。

如果你想從Java中使用讀取屬性文件,此代碼:

public class ReadPropertiesFile { 
    public static void main(String[] args) { 
     try { 
      File file = new File("test.properties");//give the properties file path 
      FileInputStream fileInput = new FileInputStream(file); 
      Properties properties = new Properties(); 
      properties.load(fileInput); 
      fileInput.close(); 

      Enumeration enuKeys = properties.keys(); 
      while (enuKeys.hasMoreElements()) { 
       String key = (String) enuKeys.nextElement(); 
       String value = properties.getProperty(key); 
       System.out.println(key + ": " + value); 
      } 
     } catch (FileNotFoundException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
}