Java J2me中的读写数据
我正在编写一个将用户数据存储到文件中的应用程序。但是,当我试图打开手机内存时,我的应用程序会引发安全异常,不允许我写入或读取数据。Java J2me中的读写数据,java,security,java-me,midp,Java,Security,Java Me,Midp,我正在编写一个将用户数据存储到文件中的应用程序。但是,当我试图打开手机内存时,我的应用程序会引发安全异常,不允许我写入或读取数据。 这是我的密码 try { FileConnection fc = (FileConnection)Connector.open("file:///C:/myfile.dat",Connector.READ_WRITE); // If no exception is thrown, the URI
这是我的密码
try
{
FileConnection fc = (FileConnection)Connector.open("file:///C:/myfile.dat",Connector.READ_WRITE);
// If no exception is thrown, the URI is valid but the folder may not exist.
if (!fc.exists())
{
fc.create(); // create the folder if it doesn't exist
}
OutputStream os=fc.openOutputStream();
String s="hello how r u..";
byte[] b=s.getBytes();
os.write(b);
os.flush();
fc.close();
}
catch(Exception error )
{
Alert alert = new Alert(error.getMessage(), error.toString(), null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
}
然而,我使用SDycard来保存数据,它工作得很好。但是,当我尝试访问手机内存时,有什么解决方案可以从SecurityException中逃脱吗?当我每次在SD卡中存储数据时,都会有一条消息提示用户允许应用程序读取或写入数据。我也不想要这个提示信息。如何摆脱这种情况?您必须签署并认证您的J2ME应用程序。这将涉及购买证书。我还没有这样做,所以你必须确认这一点,或者等待另一个答案。但我很确定,除非你在midlet上签字,否则手机的安全政策将阻止这种情况发生 一个关于如何签署midlet的URL:
您必须签署并认证您的J2ME应用程序。这将涉及购买证书。我还没有这样做,所以你必须确认这一点,或者等待另一个答案。但我很确定,除非你在midlet上签字,否则手机的安全政策将阻止这种情况发生 一个关于如何签署midlet的URL:
同意@Sethu的观点,OP是由于midlet签名 OP分为逻辑阶段以解决该问题:
MIDlet权限下添加必要的权限(对于读取:javax.microedition.io.Connector.file.read
,对于写入:javax.microedition.io.Connector.file.write
)
同意@Sethu的观点,即OP是由midlet签名引起的 OP分为逻辑阶段以解决该问题:
MIDlet权限下添加必要的权限(对于读取:javax.microedition.io.Connector.file.read
,对于写入:javax.microedition.io.Connector.file.write
)
您的链接指向仅在emulator中有效而不在设备中有效的自签名证书,请检查我的答案以获得深入的问题解决方案。您的链接指向仅在emulator中有效而不在设备中有效的自签名证书,请检查我的答案以获得深入的问题解决方案。