日期:2014-05-20  浏览次数:20872 次

有关java.security.AccessControlException的问题
写了一个程序
import   javax.swing.*;
import   java.awt.*;
import   java.awt.event.*;
import   java.io.*;
public   class   FileGUIBak   extends   JApplet   implements   ActionListener
{
private   JLabel   prompt   =   new   JLabel( "prompt ");
private   JTextField   nameInput   =   new   JTextField(20);
private   JButton   read   =   new   JButton( "ReadFile ");
private   JButton   write   =   new   JButton( "WriteFile ");
private   JTextArea   display   =   new   JTextArea(10,40);
private   JPanel   control   =   new   JPanel();
private   JPanel   displayPanel   =   new   JPanel();
private   void   writeTextFile(JTextArea   dis,   String   fileName){
try{
FileWriter   outStream   =   new   FileWriter(fileName);
outStream.write(dis.getText());
outStream.close();
}
catch(IOException   e){
display.setText( "IOERROR:   "   + e.getMessage()   +   "\n ");
e.printStackTrace();
}
}
private   void   readTextFile(JTextArea   dis,   String   fileName){
try{
BufferedReader   inStream   =   new   BufferedReader(new   FileReader(fileName));
String   line   =   inStream.readLine();
while(line   !=   null){
dis.append(line   +   "\n ");
line   =   inStream.readLine();
}
inStream.close();
}
catch(FileNotFoundException   e){
display.setText( "IOERROR:   File   NOT   Found:   "   +   fileName   +   "\n ");
e.printStackTrace();
}
catch(IOException   e){
display.setText( "IOERROR:   "   +   e.getMessage()   +   "\n ");
e.printStackTrace();
}
}
private   void   initControl(){
read.addActionListener(this);
write.addActionListener(this);
control.setBorder(BorderFactory.createTitledBorder( "Control "));
control.setLayout(new   FlowLayout());
control.add(prompt);
control.add(nameInput);
control.add(read);
control.add(write);
}
private   void   initDisplay(){
displayPanel.setBorder(BorderFactory.createTitledBorder( "Display "));
displayPanel.setLayout(new   FlowLayout());
display.setLineWrap(true);
displayPanel.add(new   JScrollPane   (display));
}
public   void   init(){
initControl();
initDisplay();
getContentPane().setLayout(new   BorderLayout());
getContentPane().add(control, "North ");
getContentPane().add(displayPanel, "Center ");
getContentPane().setSize(500,300);
}
public   void   actionPerformed(ActionEvent   e){
if(e.getSource()   ==   read){
readTextFile(display,nameInput.getText());
}
else{
writeTextFile(display,nameInput.getText());
}
}
};
和FileGUIBak.htm
<html>
<body>
<table   align= "center ">
<td>
<applet   code= "FileGUIBak.class "   width= "500 "   height= "300 ">
</applet>
</td>
</table>