问题
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