2016-06-09 75 views
0

我在嘗試使用log4j寫日誌時遇到異常。如何編寫applet應用程序的日誌文件?

這裏是拋出的異常:

java.security.AccessControlException: access denied ("java.io.FilePermission" "D:\appletServer\bqapplet.log" "write") 
    at java.security.AccessControlContext.checkPermission(Unknown Source) 
    at java.security.AccessController.checkPermission(Unknown Source) 
    at java.lang.SecurityManager.checkPermission(Unknown Source) 
    at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source) 
    at java.lang.SecurityManager.checkWrite(Unknown Source) 
    at java.io.FileOutputStream.<init>(Unknown Source) 
    at java.io.FileOutputStream.<init>(Unknown Source) 
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:294) 
    at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:207) 
    at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165) 
    at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307) 
    at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:172) 
    at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:104) 
    at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:842) 
    at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:768) 
    at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:648) 
    at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:514) 
    at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:440) 
    at com.bqurious.applet.CommandExecutor.<init>(CommandExecutor.java:41) 
    at com.bqurious.applet.BqAppletMainAppender.waitForConnections(BqAppletMainAppender.java:604) 
    at com.bqurious.applet.BqAppletMainAppender.run(BqAppletMainAppender.java:195) 
    at java.lang.Thread.run(Unknown Source) 
    Error! - java.security.AccessControlException: access denied ("java.io.FilePermission" "D:\appletServer\bqapplet.log" "write") 

回答

0

的小程序按默認運行在沙盒環境。爲了允許它訪問本地文件,您必須簽名。根據你的用例,一種不同的方法可能是登錄到標準輸出(這將在Java控制檯上提供)。

在Oracle有一個教程,您可以閱讀關於What Applets Can and Cannot Do的更多信息。

相關問題