Click here to Skip to main content
11,933,621 members (55,629 online)
Rate this:
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 "" file:
import java.applet.*;
import java.awt.*;
import java.util.Scanner;
public class fileapplet extends Applet
	public void paint(Graphics g)
		BufferedReader diskInput;
		String word;
                int a=0,b=0;  
			//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=word.toLowerCase(); // use lower case only
   		catch (IOException e) 

Following is the code for "fileapplet.html":
<applet code="fileapplet.class" width="100" height="100">
Following is the content of "Tree.txt" file:

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

1 solution

Rate this: bad
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.
reenarankawat 22-Oct-12 22:46pm
Thank you for your suggestion but I get exception "access denied ( 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 14 Oct 2012
Copyright © CodeProject, 1999-2015
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