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>