2013-06-18 64 views
1

我正在閱讀我的google appengine應用程序中的文件夾(/war/config/client.properties)中的屬性文件。它在我的本地服務器上工作正常,但它不能在生產模式下工作,並且拋出異常java.security.AccessControlException:access denied(java.io.FilePermission)。如何讀取應用程序引擎應用程序中的屬性文件?

請問您可以告訴我如何使它在生產模式下工作。

回答

4

,如果你把它放在你可以加載這樣的WEB-INF/classes中:

InputStream is = this.getClass().getClassLoader().getResourceAsStream("/client.properties"); 

同樣,你可以做

InputStream is = this.getServletContext().getResourceAsStream("/WEB-INF/client.properties"); 

然後:

Properties props = new Properties(); 
props.load(is); 
String whatever = props.getProperty("whatever_key"); 

每docs https://developers.google.com/appengine/docs/java/?hl=en-US#The_Sandbox

任何戰爭應該是默認的工作:

請在AppEngine上-web.xml中確保你沒有任何除外):

<resource-files> 
     <exclude path="**.properties"/> ...make sure you haven't done this 
    </resource-files> 

任何戰爭應該是默認的工作工作得這麼嘗試閱讀從/config/client.properties

java.io.FileReader肯定會。

InputStream is = this.getServletContext().getResourceAsStream("/config/client.properties"); 
+0

我沒有把它放在WEB-INF,如何從它在戰爭文件夾中的文件夾外部加載? –

+0

戰爭之下的任何東西都應該是一種資源,除非你排除它。嘗試/config/client.properties – user1258245

相關問題