Is it possible to save BBM chat in a text file usi

2019-09-08 11:42发布

As far as i know, i can use javax.microedition.io.file.FileConnection for the required purpose. But i need an example. Why i can't i use java.io.FileOutputStream, and use this piece of code instead:

FileOutputStream fout;      

        try
        {
            // Open an output stream
            fout = new FileOutputStream ("myfile.txt");

            // Print a line of text
            new PrintStream(fout).println ("I'm making an app on android!");

            // Close our output stream
            fout.close();       
        }
        // Catches any error conditions
        catch (IOException e)
        {
            System.err.println ("Unable to write to file");
            System.exit(-1);
        }

Please explain. Thanks

1条回答
做个烂人
2楼-- · 2019-09-08 12:11

The snipet you posted uses JavaSE classes, not available in BlackBerry.

You need to do this:

FileConnection fconn = (FileConnection)Connector.open("file:///CFCard/myfile.txt");
OutputStream os = fconn.openOutputStream();
os.write("I'm making an app on BB!".getBytes());
os.flush();
os.close();
fconn.close();

I've skipped exception control to make snippet less verbose, but you'll have to care about them as usual.

查看更多
登录 后发表回答