Is it possible to save BBM chat in a text file using J2ME in Blackberry

不羁岁月 提交于 2019-12-25 04:05:46

问题


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:


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.



来源:https://stackoverflow.com/questions/8173102/is-it-possible-to-save-bbm-chat-in-a-text-file-using-j2me-in-blackberry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!