j2me fileconnection java.io.IOException:根无法访问
FileConnection c = (FileConnection) Connector.open("file:///c:/myfile.txt",Connector.READ_WRITE);
if (c.exists())
{
System.out.println("exist");
}
else {
System.out.println("no exist");
c.create();
}
OutputStream out = c.openOutputStream();
PrintStream output = new PrintStream( out );
output.println( response );
out.close();
c.close();
在上面的代码中,我收到以下错误:
no exist
java.io.IOException: Root is not accessible
at com.sun.midp.io.j2me.file.Protocol.ensureConnected(Protocol.java:1588)
at com.sun.midp.io.j2me.file.Protocol.ensureOpenAndConnected(Protocol.java:1604)
at com.sun.midp.io.j2me.file.Protocol.create(Protocol.java:945)
at hello.Midlet.traverse(Midlet.java:83)
at hello.Midlet.startApp(Midlet.java:40)
at javax.microedition.midlet.MIDletProxy.startApp(MIDletProxy.java:43)
at com.sun.midp.midlet.Scheduler.schedule(Scheduler.java:374)
at com.sun.midp.main.Main.runLocalClass(Main.java:466)
at com.sun.midp.main.Main.main(Main.java:120)
文件 file:\\c:\myfile.txt 存在。我现在该怎么办?
FileConnection c = (FileConnection) Connector.open("file:///c:/myfile.txt",Connector.READ_WRITE);
if (c.exists())
{
System.out.println("exist");
}
else {
System.out.println("no exist");
c.create();
}
OutputStream out = c.openOutputStream();
PrintStream output = new PrintStream( out );
output.println( response );
out.close();
c.close();
in the above code I m getting the following error:
no exist
java.io.IOException: Root is not accessible
at com.sun.midp.io.j2me.file.Protocol.ensureConnected(Protocol.java:1588)
at com.sun.midp.io.j2me.file.Protocol.ensureOpenAndConnected(Protocol.java:1604)
at com.sun.midp.io.j2me.file.Protocol.create(Protocol.java:945)
at hello.Midlet.traverse(Midlet.java:83)
at hello.Midlet.startApp(Midlet.java:40)
at javax.microedition.midlet.MIDletProxy.startApp(MIDletProxy.java:43)
at com.sun.midp.midlet.Scheduler.schedule(Scheduler.java:374)
at com.sun.midp.main.Main.runLocalClass(Main.java:466)
at com.sun.midp.main.Main.main(Main.java:120)
The file file:\\c:\myfile.txt exists. How do i go about now ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您需要设置 MIDLet 权限。
请注意,您可能可以在模拟器上使用此功能,但至少需要签名代码才能在真实设备上使用。
Looks like you need to set the MIDLet Permissions.
Note you might get this working on the simulator but you will need signed code at least to get working on a real device.