Question

Okay so I was parsering an XML file using JAVA DOM. Whenever the program gets to the point where it is supposed to parser the XML file, I get a "AccessControlException" saying "access denied". I have parsered many XML files using JAVA DOM and this is the first time I have gotten this exception. What am I doing wrong?

Here is the XML file:

<?xml version="1.0" encoding="UTF-8" ?>
<root>

</root>

Here is the code that is supposed to parser it:

DocumentBuilderFactory bdf = DocumentBuilderFactory.newInstance();
        DocumentBuilder bd = bdf.newDocumentBuilder();
        Document doc = bd.parse("excersize.xml");

Finally here is the error I get:

java.security.AccessControlException: access denied ("java.io.FilePermiss
ion" "\excersize.xml" "read")

Edit

Luckily after some time I got it to work using a policy file however for whatever reason it only works if I type the full directory of the xml file

This works:

Document doc = builder.parse("file:/B:/Programming/Java/Programs/new/excersize.xml");

but this doesn't:

Document doc = builder.parse("excersize.xml"); //The xml file is in the same directory as the java source file, the class file, and the html file

although this is tolerable, I do like to keep my files "mobile ready" so that they don't have any concrete adresses but rather adresses relative to the .java and .class file. Any help at all to help me figure out this problem would be greatly appreciated :)

Was it helpful?

Solution

The exception says it all, you are trying to access a file the JVM can't access. Maybe you can take a look at the documentation

EDIT

By default, applets can't access the client's file I/O. You need to sign your applet or edit the policy files to allow it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top