tags:

views:

112

answers:

2

I have the below method which is meant to append information to a file but I get the error below. In the method I use parts of robocode API which inherits from java.io.InputStream

All the permissions on the files and folders seem fine and the file does exist

static public void logInfo(String info) 
{        

    RobocodeFileWriter in;
    try {
        in = new RobocodeFileWriter("log.txt");
        in.append(info);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }       


}

SYSTEM: An error occurred during initialization of itc.solomon SYSTEM: java.security.AccessControlException: Preventing itc.solomon from access: (java.io.FilePermission log.txt read): You may only read files in your own root package directory. java.security.AccessControlException: Preventing itc.solomon from access: (java.io.FilePermission log.txt read): You may only read files in your own root package directory. at robocode.security.RobocodeSecurityManager.handleSecurityProblem(Unknown Source) at robocode.security.RobocodeSecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkRead(SecurityManager.java:888) at java.io.File.exists(File.java:748) at robocode.RobocodeFileOutputStream.(Unknown Source) at robocode.RobocodeFileOutputStream.(Unknown Source) at robocode.RobocodeFileWriter.(Unknown Source) at itc.CFile.logInfo(CFile.java:16) at itc.solomon.(solomon.java:43) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:532) at java.lang.Class.newInstance0(Class.java:372) at java.lang.Class.newInstance(Class.java:325) at robocode.peer.proxies.HostingRobotProxy.loadRobotRound(Unknown Source) at robocode.peer.proxies.HostingRobotProxy.run(Unknown Source) at java.lang.Thread.run(Thread.java:636)

+1  A: 

I've searched a bit about this problem. It seems that there's a bug in the robocode package, awkwardly solved by:

while (!dataIsLoaded) {
   try {
       tryToReadData;
       dataIsLoaded = true;
   } catch (AnyException e) {}
}

It's a quite awful way to solve the problems, for many reasons (ignoring exceptions, busy-waiting, etc.) A more sane way would be downgrading the robocode package to a previous, more stable version.

See search results here.

Adam Matan
Pavel Savara
+1  A: 

See this sample: http://code.google.com/p/robocode/source/browse/robocode/trunk/robocode.samples/src/main/java/sample/SittingDuck.java

I think getDataFile("log.txt") will give you proper location.

Pavel Savara