黑莓:将文件保存到文本文件

发布于 2024-12-26 01:53:09 字数 1273 浏览 1 评论 0原文

我愿意制作一个简单的应用程序,根据此 条目,但我面临着一个令人沮丧的异常。

这是我的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

微暖i 2025-01-02 01:53:09

检查您的模拟器是否已安装 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.

2025-01-02 01:53:09

好吧,答案很棘手。我不断尝试使用相同的代码,直到我开始认为这是与模拟器相关的问题,所以我所做的是,在运行应用程序之前,我删除插入< /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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文