Error reading if. arff file exists or not

Asked

Viewed 84 times

0

I am developing a robot in JAVA along with the Robocode framework and WEKA. Whenever I try to check if the file ". arff" exists, always gives me the same mistake.

Round 1 initializing..

Let the games Begin!

Preventing Interative_newversion.Newrobot_interative* from access: ("java.io.Filepermission" "C: Users Josedias Documents Netbeansprojects Interativepower.arff" "read"). You may only read files in your Own root package directory.

.Interative_newversion.Newrobot_interative* has caused security Violation. This robot has been banned and will not be allowed to participate in Battles.

Interative_newversion.Newrobot_interative*: Exception: java.security.Accesscontrolexception: access denied ("java.io.Filepermission" "C: Users Josedias Documents Netbeansprojects Interativepower.arff" "read")

The next line is the line I use to check whether or not the file exists at a given location.

@Override
public boolean datasetExists(String path) {

    File dc = new File(path);
  return   dc.exists();


}

What might be the related problem?

1 answer

1


Friend, your code is not allowed to access the file.

Add the following lines below the reference variable dc:

    dc.setReadable(Boolean.FALSE);
    dc.setWritable(Boolean.FALSE);
    dc.setExecutable(Boolean.FALSE);

Why FALSE? A: because by setting false, you tell the system that you want everyone to have access to the file. If you inform True, only the file Owner will have access, which is strange in the contrary of the standard for Boolean cases, but that’s okay.

Source: https://develoraptor.wordpress.com/2012/04/02/manipulando-permissoes-de-arquivos-em-java/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.