j2me中文件处理中的安全异常

时间:2010-05-22 09:38:48

标签: java java-me

我正在尝试生成一个日志文件。

static String fname="file:///c:/logfile.txt;append=true";
fc = (FileConnection) Connector.open(fname, Connector.WRITE);
if (fc.exists()) {
  // file exists, open at EOF.
  offset = fc.fileSize();
  os = fc.openOutputStream(offset);
} else {
  // file does not exist, create and open.
  fc.create();
  os = fc.openOutputStream();
}

获得以下异常

java.lang.SecurityException: Access denied
  at com.symbian.midp.io.protocol.file.FileConnectionImpl.open(FileConnectionImpl.java:71)
  at com.symbian.midp.io.protocol.file.Protocol.openConnection(Protocol.java:40)
  at com.symbian.gcf.ProtocolBase.openConnection(), bci=159
  at com.symbian.gcf.GCFConnector.open(), bci=237
  at com.symbian.j2me.midp.legacy.LegacyConnectionFactory.open(LegacyConnectionFactory.java:35)
  at com.symbian.j2me.midp.runtimeV2.ConnectionService.open(), bci=8
  at javax.microedition.io.Connector.open(), bci=6
  at javax.microedition.io.Connector.open(Connector.java:48)
  at Symbian.LogFile.FileOpen(LogFile.java:27)
  at Symbian.Symbian.startApp(Symbian.java:216)
  at javax.microedition.midlet.MIDletInvoker.invokeStartApp(MIDletInvoker.java:30)
  at com.symbian.j2me.midp.runtimeV2.Application.startAction(Application.java:458)
  at com.symbian.j2me.midp.runtimeV2.Application.startRequest(Application.java:413)
  at com.symbian.j2me.midp.runtimeV2.Application.event(Application.java:264)
  at com.symbian.j2me.midp.runtimeV2.ApplicationEvent.dispatch(ApplicationEvent.java:90)
  at com.symbian.j2me.midp.runtimeV2.ApplicationThread.run(ApplicationThread.java:30)

拒绝访问

1 个答案:

答案 0 :(得分:0)

更改

static String fname="file:///c:/logfile.txt;append=true";

static String fname="file:///c:/logfile.txt";