Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Applet
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:
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>
<applet code="fileapplet.class" width="100" height="100">
</applet>
</html>    
 
Following is the content of "Tree.txt" file:

56 78 87 54
Posted 13-Oct-12 1:49am
Edited 13-Oct-12 1:56am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
reenarankawat at 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)

  Print Answers RSS
0 OriginalGriff 325
1 DamithSL 300
2 Sergey Alexandrovich Kryukov 289
3 CPallini 235
4 Maciej Los 215
0 OriginalGriff 5,455
1 DamithSL 4,422
2 Maciej Los 3,860
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,010


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 14 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100