dcsimg
Java I/O vs JApplet
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Albert_Leng
Posted On:   Wednesday, January 16, 2002 02:42 PM

I'm trying to create an applet to read from a text file (image1.txt) which has only "image1.jpg" (excluding the quote). The applet will read from the text file and load the image using the string in the text file, ie "image1.jpg" but the problem is the applet can't be initialised and the following is displayed in the Java console: ava.security.AccessControlException: access denied (java.io.FilePermission image1.txt read) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkRead(Unknown Sour   More>>

I'm trying to create an applet to read from a text file (image1.txt) which has only "image1.jpg" (excluding the quote). The applet will read from the text file and load the image using the string in the text file, ie "image1.jpg" but the problem is the applet can't be initialised and the following is displayed in the Java console:

ava.security.AccessControlException: access denied (java.io.FilePermission image1.txt read)


at java.security.AccessControlContext.checkPermission(Unknown Source)


at java.security.AccessController.checkPermission(Unknown Source)


at java.lang.SecurityManager.checkPermission(Unknown Source)


at java.lang.SecurityManager.checkRead(Unknown Source)


at java.io.FileInputStream. (Unknown Source)


at java.io.FileReader. (Unknown Source)


at ImageDisplay.init(ImageDisplay.java:15)


at sun.applet.AppletPanel.run(Unknown Source)


at java.lang.Thread.run(Unknown Source)


I'm sure that it's something to do with security restriction in Java. How can i prevent that? The following is my code:

import javax.swing.*;

import java.util.StringTokenizer;

import java.io.*;

import java.awt.*;

public class ImageDisplay{

private Image image1;

private StringTokenizer tokenizer;

private String line,imageName, fileName= "image1.txt";

private FileReader fr;

private BufferedReader inFile;


public void init(){

try{

FileReader fr = new FileReader(fileName);

BufferedReader inFile = new BufferedReader(fr);

line = inFile.readLine();


while(line != null)

{

tokenizer = new StringTokenizer(line);

imageName = tokenizer.nextToken();

line = inFile.readLine();

}

inFile.close();

}


catch(FileNotFoundException exception)

{

System.out.println("The file " + fileName + " was not found.");

}


catch (IOException exception)

{

System.out.println(exception);

}


image1 = getImage(getDocumentBase(),imageName);

}


public void paint(Graphics g){

g.drawImage(image1,5,5,this);

}

}


Please give your opinions and advice... Thanks a lot!

   <<Less

Re: Java I/O vs JApplet

Posted By:   frank_jania  
Posted On:   Wednesday, January 16, 2002 10:37 PM

i don't see where in the sample code you reference an applet, but in short the answer to your question of security is that you'll need to use the 'policytool' to allow applets to do file i/o on each machine that you want to run this on.
About | Sitemap | Contact