Click to See Complete Forum and Search --> : Applet works in appletviewer, but not in browser


Malone
09-11-2004, 10:07 PM
java.security.AccessControlException: access denied (java.io.FilePermission words.txt read)


There is the error in my Java Control Panel Console thingy when I try to load my applet in a browser. I've tried IE and FireFox. Are applets unable to read files located in the same directory as the applet? Or is there something simple I have to change?


// build the dictionary tree
String dictionaryFN = "words.txt";
try
{
BufferedReader fin = new BufferedReader(new FileReader(dictionaryFN));
String word = fin.readLine();
while (word != null)
{
dictionary.insert(word);
word = fin.readLine();
}
fin.close();
}
catch (FileNotFoundException e)
{
System.err.println("FileNotFoundException: " + e.getMessage());
return false;
}
catch (IOException e)
{
System.err.println("IOException: " + e.getMessage());
return false;
}


There is the code in question. Maybe I'm doing something wrong? Any help is appreciated.

rock
09-12-2004, 08:41 PM
You can't read files off the harddrive in an Applet, it's part of the Java sandbox security model. If you package everything in a jar file, you can then access files as resources. I can give you code examples if you need them (it's been a while since I've done it and would have to look it up).

Malone
09-16-2004, 12:25 AM
Thanks, that makes sense. I'll jar it up then, I'm sure I can figure out the resource thing on my own. :)