Blackberry Api:将字节数组写入文件

发布于 2024-11-25 00:29:37 字数 540 浏览 1 评论 0原文

我正在尝试从 mp3 文件读取和写入元数据。我可以读取数据,但不知道如何写入。

我使用以下代码来获取文件访问权限:

FileConnection file = (FileConnection) Connector.open("file:///store/home/user/music/song.mp3");
if(file.exists())
         java.io.InputStream inputStream = file.openInputStream();

稍后,我使用以下代码读取数据:

buffer = new byte[length]; // length is predetermined earlier
if (inputStream.read(buffer, 0, length) == length)
         String info = new String((buffer));

如何将数据(字节)写入文件中的指定位置?我不确定输出字节所需的 IO 声明和特定代码。

I am trying to read and write metadata to/from an mp3 file. I can read the data, but I cannot figure out how to write it.

I use the following code to get file access:

FileConnection file = (FileConnection) Connector.open("file:///store/home/user/music/song.mp3");
if(file.exists())
         java.io.InputStream inputStream = file.openInputStream();

Later, I read the data using the following code:

buffer = new byte[length]; // length is predetermined earlier
if (inputStream.read(buffer, 0, length) == length)
         String info = new String((buffer));

How do I write data (bytes) to the a designated location in the file? I am unsure of both the IO declarations and the specific code required to output my bytes.

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

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

发布评论

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

评论(1

断舍离 2024-12-02 00:29:37

要在 Blackberry 上写入文件,请使用以下代码:

    FileConnection fconn = null;
    OutputStream out = null;
    try {
        fconn = (FileConnection) Connector.open(yourFileNameAndPath,Connector.READ_WRITE);
    }
    fconn.create();
    out = fconn.openOutputStream();
    out.write(yourDataBytes);
    out.flush();
    fconn.close();

To write a file on Blackberry use the following code:

    FileConnection fconn = null;
    OutputStream out = null;
    try {
        fconn = (FileConnection) Connector.open(yourFileNameAndPath,Connector.READ_WRITE);
    }
    fconn.create();
    out = fconn.openOutputStream();
    out.write(yourDataBytes);
    out.flush();
    fconn.close();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文