background image

public void actionPerformed(ActionEvent e){
loadFile(fileNameField.getText());
}
});
panel.add(b);
this.add(panel,BorderLayout.NORTH);
fileArea=new TextArea();
this.add(fileArea,BorderLayout.CENTER);
}
public void loadFile(String fileName){
try{
BufferedReader reader=new BufferedReader(new FileReader(fileName));
String context=new String();
while((context=reader.readLine())!=null){
fileArea.append(context+"/n");
}
reader.close();
}catch(IOException ie){
fileArea.append(ie.getMessage());
}catch(SecurityException se){
fileArea.append("because of security constraint ,it can not do that!");
}
}
file://Get Applet information
public String getAppletInfo() {
return "This is an applet can read and write the local file system";
}

  如果你将这个代码嵌入网页中并执行它,当你试图打开一个本地文件时就会发生
SecurityException。大家跟着我进行下面的步骤就可以最终拥有读写文件的权限。在此之前
你需要有以下的工具:JDK1.1 以上、JRE、HTMLConvert。这些工具在 SUN 的 Java 站点上
都有,而且也是免费的。将它们分别安装好,我们将所有涉及的文件都放在 c:/admin 中。

打包的名称要跟类 packeg 的名称使用的名称一致

  步骤一:(打包 class 文件)

  在命令行中执行以下的语句:jar -cvf MyApplet.jar class

  注意这里的所有.class 文件均是放在一个 class 的目录中的。本步骤执行完毕后,将在
c:/admin 中产生一个名为 MyApplet.jar 的文件。

  步骤二:(在网页中嵌入 Applet)