• Advertisement

Archived

This topic is now archived and is closed to further replies.

[java] applet security exception

This topic is 5779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I get this exception when tryin to run my applet in IE. com.ms.security.SecurityExceptionEx[Trayracer.render]: java.io.IOException: bad path: C:\Programering\igglacer\java\util\Collection.class at com/ms/security/permissions/FileIOPermission.check (FileIOPermission.java) The problems began when I made a class that get a url (from getCodeBase()) and loads some stuff and store it into a vector. Need I say that it works fine in the appletviewer. Frustrating... Any tip welcome

Share this post


Link to post
Share on other sites
Advertisement
Applets have extremely high security features enabled. They cannot interact with other computers (through Sockets, FileIO, JDBC, anything). If you want your applet to work correctly with your file you need to have them both hosted on the same server.


Appletviewer is a special case for applets, it sets their security to zilch so that you can test your applet before deploying it.

Share this post


Link to post
Share on other sites
this is how i read from files in applets:


  
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;

public class FileManager {
private static FileManager singleInstance;

private FileManager() {}

public static FileManager instance() {
if(singleInstance == null)
singleInstance = new FileManager();
return singleInstance;
}

public String loadData(String fileName) {
InputStream inStream = this.getClass().getResourceAsStream(fileName);
BufferedReader in = new BufferedReader(new InputStreamReader(inStream));
StringBuffer output = new StringBuffer();
try {
String oneLine = in.readLine();
while (oneLine != null) {
output.append(oneLine+"\n");
oneLine = in.readLine();
}
}
catch (Exception e) {System.out.println("Error reading from file: "+fileName);}
return output.toString();
}
}


it''s easy to adapt to your needs.

_______________________
http://mill.3dfxsweden.net

Share this post


Link to post
Share on other sites
you may not have enough permission to read files of the disk.
java applets have high security..

run policytool
you can add a policy for allowing java applets to read files from the disk.

{ Stating the obvious never helped any situation !! }

Share this post


Link to post
Share on other sites
Thanks for replying. I think that I have grasped the concept of an applet but..
I´ll try making my problem a little clearer by posting some code:


  
public class Igglacer extends Applet implements Runnable
{
...
trayracer.render(getGraphics(), getSize().width, getSize().height, getDocumentBase());
...
}

// in the defenition of trayracer

public void render(Graphics g, int width, int height, URL url )
{
Vector primitives;
...
primitives.addAll(i3ds.importFromURL(new URL(url,"mesh/mesh.3ds"), material));
...
}

// in the defenition of i3ds

public Vector importFromURL(URL url, Material mat) throws IOException
{
InputStream inStream = url.openStream();
BufferedInputStream in = new BufferedInputStream(inStream);
...
}


My questions/problems :
Is it my file I/O code that is causing the exception. It keeps buggin me ´bout Collection.class. Can that cause a sec. excpt? Little me using the class Vector I mean?

Share this post


Link to post
Share on other sites
If anyone is interested...
I solved my problem. The security exception came from Vector::addAll(x) ? When I iterate over the vector instead and add each element manually the exception goes away. This seems strange to me but it works.

Share this post


Link to post
Share on other sites

  • Advertisement