在 BlackBerry 上使用流保存和读取文件

发布于 2024-10-02 04:37:10 字数 1142 浏览 0 评论 0原文

参数“address”是字符串“CepVizyonVersionFile”,在 Connector.openDataInputStream(address) 之后,程序会抛出异常并显示消息:

网址中没有“:”。

地址应该采用什么格式?

public void saveLocal(String fileString, String address) {
        try {
            DataOutputStream fos = Connector.openDataOutputStream(address); //openFileOutput(address);
            fos.write(fileString.getBytes());
            fos.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

}

public String readLocal(String address, int lenght) {
    byte[] buffer = new byte[lenght];
    byte[] buffer2;
    String str = new String();
    try {
        DataInputStream fis = Connector.openDataInputStream(address);
        int lnght = fis.read(buffer);
        buffer2 = new byte[lnght];
        fis.close();
        for (int i = 0; i < lnght; i++)
            buffer2[i] = buffer[i];
        str = new String(buffer2);
    }  catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return str;
}

Argument 'address' is the string "CepVizyonVersionFile", and after Connector.openDataInputStream(address) the program throws an exception with message:

no ' : ' in URL.

What format should address be in?

public void saveLocal(String fileString, String address) {
        try {
            DataOutputStream fos = Connector.openDataOutputStream(address); //openFileOutput(address);
            fos.write(fileString.getBytes());
            fos.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

}

public String readLocal(String address, int lenght) {
    byte[] buffer = new byte[lenght];
    byte[] buffer2;
    String str = new String();
    try {
        DataInputStream fis = Connector.openDataInputStream(address);
        int lnght = fis.read(buffer);
        buffer2 = new byte[lnght];
        fis.close();
        for (int i = 0; i < lnght; i++)
            buffer2[i] = buffer[i];
        str = new String(buffer2);
    }  catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return str;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

沫尐诺 2024-10-09 04:37:10

你把你的文件放在哪里?
如果它在媒体卡上,你的地址应该是这样的:“file:///SDCard/”+你的文件名。

Where do you put your file?
If it is on the media card, your address should be like this: "file:///SDCard/"+yourfilename.

上课铃就是安魂曲 2024-10-09 04:37:10

Connector 的 BlackBerry API 文档格式说明:

描述目标的参数字符串应符合 RFC 2396 中描述的 URL 格式。这采用一般形式:
{方案}:[{目标}][{参数}]
其中 {scheme} 是协议的名称,例如 http。

{target} 通常是某种网络地址。

任何 {parms} 均由一系列“;x=y”形式的等式组成。示例:“;type=a”。

并且还列出了支持的方案:

通讯
套接字
UDP
短信
彩信
http
https
tls 或 ssl
蓝牙串口简介

由于您需要文件,因此需要查看 javax.microedition.io.file

用于通过 Connector.open() 访问 FileConnection 的输入字符串的格式必须遵循完全限定的绝对路径文件名的格式,如 IETF RFC 1738 和 IETF RFC 1738 的一部分的文件 URL 格式中所述。 2396. 该 RFC 规定文件 URL 采用以下形式:

文件://<主机>/<路径>

The BlackBerry API documentation for Connector has an explanation of the format:

The parameter string that describes the target should conform to the URL format as described in RFC 2396. This takes the general form:
{scheme}:[{target}][{parms}]
where {scheme} is the name of a protocol such as http.

The {target} is normally some kind of network address.

Any {parms} are formed as a series of equates of the form ";x=y". Example: ";type=a".

and the supported schemes are listed as well:

comm
socket
udp
sms
mms
http
https
tls or ssl
Bluetooth Serial Port Profile

Since you want a file, you'll need to take a look at the package documentation for javax.microedition.io.file

The format of the input string used to access a FileConnection through Connector.open() must follow the format for a fully qualified, absolute path file name as described in the file URL format as part of IETF RFCs 1738 & 2396. That RFC dictates that a file URL takes the form:

file://<host>/<path>

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