|
我现在用java applet来create一个txtfile。可是面对access denied的error...请问是哪里出了问题??
error:
java.security.AccessControlException: access denied (java.io.FilePermission temprec.txt write)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
at java.security.AccessController.checkPermission(AccessController.java:427)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkWrite(SecurityManager.java:962)
at java.io.FileOutputStream.<init>(FileOutputStream.java:169)
at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
at java.io.FileWriter.<init>(FileWriter.java:73)
at Thermometer.init(Thermometer.java:24)
at sun.applet.AppletPanel.run(AppletPanel.java:378)
at java.lang.Thread.run(Thread.java:595)
以下是我的code:(如果不要用在applet,这code就没问题)
public void init()
{
File tempfile = new File("test.txt");
if (!tempfile.exists())
{
try
{
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(tempfile));
String toencode = "Cp437 text";
String encoded = new String(toencode.getBytes("Cp437"),"Cp437");
bufferedWriter.write(toencode);
bufferedWriter.flush();
}
catch (IOException e)
{
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
} |
|