Skip to main content
gamedev.net
🔒 Locked

[java] AccessControlException

Started by The_True_Bow_Master Dec 18, 2004 at 7:49 PM 2 replies 650+ views
Original Post
The_True_Bow_Master
The_True_Bow_Master
I am working on my first Java Game and it's almost complete, except that I get an AccessControlException when I try to write to a file. I am not sure how to get the permission...is it with a policyfile or can I do something else? Here is the error: java.security.AccessControlException: access denied (java.io.FilePermission score.dat write) at java.security.AccessControlContext.checkPermission(AccessControlContext.java:269) at java.security.AccessController.checkPermission(AccessController.java:401) at java.lang.SecurityManager.checkPermission(SecurityManager.java:524) at java.lang.SecurityManager.checkWrite(SecurityManager.java:954) at java.io.FileOutputStream.(FileOutputStream.java:169) at java.io.FileOutputStream.(FileOutputStream.java:70) at java.io.FileWriter.(FileWriter.java:46) at Game1945.paint(Game1945.java:392) at javax.swing.JApplet.update(JApplet.java:143) at sun.awt.RepaintArea.paint(RepaintArea.java:169) at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260) at java.awt.Component.dispatchEventImpl(Component.java:3678) at java.awt.Container.dispatchEventImpl(Container.java:1627) at java.awt.Component.dispatchEvent(Component.java:3477) at java.awt.EventQueue.dispatchEvent(EventQueue.java:456) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137) at java.awt.EventDispatchThread.run(EventDispatchThread.java:100) Here is my code that is erroring: try { PrintWriter outFile = new PrintWriter(new FileWriter("score.dat")); for(int x = 0; x < 10; x++) { outFile.println(nameList[x]); outFile.println(scoreList[x]); } outFile.close(); } catch(IOException e){}
SamLowry
SamLowry
Security exceptions are only raised when a security manager has been activated. If you're running your game on your own PC, security is no issue (I'm sure you trust yourself not to have accidently written an application which formats your harddisk).

If it's a stand-alone application, I don't think a security manager (SM) is activated by default; applets however should have the SM enabled.
My guess is that you're creating an applet.

I have no experience with applet security, so I'll just give you a possibly interesting webpage I've found.


In the case of a stand-alone app and you want to keep the SM activated, you can write a policy file which grants your code write access to specific files. Link

If you're more specific about your problem, I may be able to provide you with a more specific solution.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.