【发布时间】:2011-12-30 07:56:45
【问题描述】:
我正在编写一个将用户数据存储到文件中的应用程序。但是,当我尝试打开手机内存时,我的应用程序会引发安全异常,并且不允许我写入或读取数据。
这是我的代码。
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 中逃脱?当我每次将数据存储在 SDCARD 中时,都会提示一条消息,要求用户允许应用程序读取或写入数据。我也不想要这个提示信息。
如何摆脱这种情况?
【问题讨论】:
标签: java security java-me midp