Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Below is the java source code where I am trying to read a file and want to display its content on an applet which is opened through a html page. The problem is that when I try to open the applet through appletviewer there is not problem the data is displayed successfully but the same does not happens then I open the applet through the browser.

I am not getting what is the problem in opening the same file through browser.

Please help...


Following is the code for "fileapplet.java" file:
Java
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.util.Scanner;

public class fileapplet extends Applet
{
	public void paint(Graphics g)
	{
		BufferedReader diskInput;
		String word;
                int a=0,b=0;  
		try 
		{ 
			//reads in words from a file
      		diskInput = new BufferedReader(new InputStreamReader(new FileInputStream("Tree.txt")));
			// file name is on command line
      		Scanner input=new Scanner(diskInput);

	     		while (input.hasNext()) 
			{ 
        			word=input.next();
        			word=word.toLowerCase(); // use lower case only
				g.drawString(word,a,b);
                                a+=10;
                                b+=10;
      		}
    		}
   		catch (IOException e) 
		{
      	}		
	} 
}


Following is the code for "fileapplet.html":
HTML
<html>
<applet code="fileapplet.class" width="100" height="100">
</applet>
</html>    

Following is the content of "Tree.txt" file:

56 78 87 54
Posted
Updated 13-Oct-12 0:56am
v2

1 solution

Your applet doesnt have permission to do read/write I/O.
You need to sing the applet or update your .java.policy file to give access permissions.
 
Share this answer
 
Comments
reenarankawat 22-Oct-12 22:46pm    
Thank you for your suggestion but I get exception "access denied (java.io.FilePermission Tree.txt write)" even after getting the applet signed. What must I do now. Please help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900