Applet works in appletviewer, but not in browser

Sharky Forums


Results 1 to 3 of 3

Thread: Applet works in appletviewer, but not in browser

  1. #1
    Tiger Shark
    Join Date
    Oct 2000
    Location
    Erie, PA, USA
    Posts
    693

    Applet works in appletviewer, but not in browser

    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?

    Code:
    		// 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.
    AMD AthlonXP 2600+ Thoroughbred B @ 200x10.5
    Shuttle AN35N nForce2 Ultra 400
    2x512MB Kingston PC3200 (3-3-3)
    ATI Radeon 9600 Pro
    40GB WD ATA-100 8MB cache
    Creative 12X DVD Drive
    Memorex 52X CD-RW
    Running Windows XP Pro

  2. #2
    NullPointerException rock's Avatar
    Join Date
    Sep 2000
    Location
    York, PA
    Posts
    6,203
    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).

    Open Source is free like a puppy is free.

    It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.

    Understanding Evolution

  3. #3
    Tiger Shark
    Join Date
    Oct 2000
    Location
    Erie, PA, USA
    Posts
    693
    Thanks, that makes sense. I'll jar it up then, I'm sure I can figure out the resource thing on my own.
    AMD AthlonXP 2600+ Thoroughbred B @ 200x10.5
    Shuttle AN35N nForce2 Ultra 400
    2x512MB Kingston PC3200 (3-3-3)
    ATI Radeon 9600 Pro
    40GB WD ATA-100 8MB cache
    Creative 12X DVD Drive
    Memorex 52X CD-RW
    Running Windows XP Pro

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •