黑莓:将文件保存到文本文件
我愿意制作一个简单的应用程序,根据此 条目,但我面临着一个令人沮丧的异常。
这是我的代码:
private boolean saveFile(String fileName, String fileContent) {
DataOutputStream os = null;
FileConnection fconn = null;
try {
fconn = (FileConnection)Connector.open(fileName,Connector.READ_WRITE);
if (!fconn.exists())
fconn.create();
os=fconn.openDataOutputStream();
String myString=fileContent;
os.write(myString.getBytes());
os.close();
fconn.close();
} catch (IOException e) {
// TODO Auto-generated catch block
Dialog.alert(e.toString());
return false;
}
return true;
}
private String getFileName() {
return "file:///SDCard/BlackBerry/documents/text.dat";
}
这是我得到的异常:
net.rim.device.api.io.file.FileIOException: File system error
API 说了以下内容:
IOException - if the firewall disallows a connection that is not btspp or comm.
我不知道这是否有帮助。
我正在使用 BlackBerry JRE 4.6.1 和 BlackBerry 8900 Simulator。 希望你们能帮助我。
I was willing to make a simple application that stores data in a text file according to this entry but I am facing a frustrating exception.
This is my code:
private boolean saveFile(String fileName, String fileContent) {
DataOutputStream os = null;
FileConnection fconn = null;
try {
fconn = (FileConnection)Connector.open(fileName,Connector.READ_WRITE);
if (!fconn.exists())
fconn.create();
os=fconn.openDataOutputStream();
String myString=fileContent;
os.write(myString.getBytes());
os.close();
fconn.close();
} catch (IOException e) {
// TODO Auto-generated catch block
Dialog.alert(e.toString());
return false;
}
return true;
}
private String getFileName() {
return "file:///SDCard/BlackBerry/documents/text.dat";
}
This is the exception I get:
net.rim.device.api.io.file.FileIOException: File system error
The API says the following:
IOException - if the firewall disallows a connection that is not btspp or comm.
which I don't know if might be helpful or not.
I am using BlackBerry JRE 4.6.1 and a BlackBerry 8900 Simulator.
Hope you guys can help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查您的模拟器是否已安装 SDCard。
如果您是自动启动,则必须等到系统完全启动并安装 SDCard: 示例
最后 - 您还必须在失败的操作结束时关闭流和文件连接。
Check that your simulator has mounted SDCard.
If your is autostart you have to wait until system is completely powered up and SDCard is mounted: example
And the final - you have to close streams and file connection at the end of failed operation also.
好吧,答案很棘手。我不断尝试使用相同的代码,直到我开始认为这是与模拟器相关的问题,所以我所做的是,在运行应用程序之前,我删除并插入< /em> 使用 Blackberry 界面菜单中的
Options
项插入 SD 卡,仅此而已。它就像魅力一样起作用。我猜这是模拟器中的一个错误。Ok, the answer is tricky. I kept trying with the same code over and over until I started to think that it was a problem related to the simulator so what I did is, before running the application, I removed and inserted the SD card using the
Options
item from the Blackberry interface menu and that was it. It worked like charm. I guess it is a bug in the simulator.