查看: 898|回复: 2
|
java applet(紧急)
[复制链接]
|
|
我现在用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());
}
}
} |
|
|
|
|
|
|
|
发表于 30-11-2006 12:12 AM
|
显示全部楼层
原帖由 CoLoUrGhOsT 于 29-11-2006 12:39 PM 发表
我现在用java applet来create一个txtfile。可是面对access denied的error...请问是哪里出了问题??
error:
java.security.AccessControlException: access denied (java.io.FilePermission temprec.txt write) ...
很久以前试过,新的JDK就不知道是不是一样
在你实行applet class那个folder里,增加一个file取名为比如说 all.policy
那个档案存放这些东西
grant {
permission java.io.FilePermission "<<ALL FILES>>", "write";
};
(意思是-所有的file都可以自由的写入)
然后开始实行appletviewer.
如果你的html名字是 writefile.html 的话
你就照一下的command
appletviewer -J"-Djava.security.policy=all.policy" writefile.html |
|
|
|
|
|
|
|
楼主 |
发表于 30-11-2006 09:11 PM
|
显示全部楼层
原帖由 jllp 于 30-11-2006 12:12 AM 发表
很久以前试过,新的JDK就不知道是不是一样
在你实行applet class那个folder里,增加一个file取名为比如说 all.policy
那个档案存放这些东西
grant {
permission java.io.FilePermission "< ...
可以了。。非常谢谢,可是run了我的code后,会有很多东东出来,请问是什么?
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: component
argument pData
at sun.awt.windows.Win32SurfaceData.initOps(Native Method)
at sun.awt.windows.Win32SurfaceData.<init>(Win32SurfaceData.java:448)
at sun.awt.windows.Win32SurfaceData.createData(Win32SurfaceData.java:316
)
at sun.awt.Win32GraphicsConfig.createSurfaceData(Win32GraphicsConfig.jav
a:357)
at sun.awt.windows.WComponentPeer.replaceSurfaceData(WComponentPeer.java
:332)
at sun.awt.windows.WComponentPeer.replaceSurfaceData(WComponentPeer.java
:313)
at sun.awt.windows.WComponentPeer$2.run(WComponentPeer.java:353)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110) |
|
|
|
|
|
|
| |
本周最热论坛帖子
|