我正在我的黑莓应用程序中重复使用一些安卓代码。有一行代码是这样的
File f = new File(cacheDir, filename);
其中 cacheDir 是一个文件,文件名是一个字符串。 但是当在黑莓中实现同一行时,我得到了错误
"The constructor File(File, String) is undefined".
谁能帮帮我。
更新
我面临的另一个错误是这一行
OutputStream os = new FileOutputStream(f);
其中 f
是 FileConenction 流的实例。错误说
"The constructor FileOutputStream(FileConnection) is undefined"
谁能帮忙?
最佳答案
通常的 File
Java API 在 BB 上不起作用。
请参阅 javax.microedition.io.Connector
和 javax.microedition.io.file.FileConnection
的 BB API 文档。
您需要执行以下操作:
FileConnection fconn = (FileConnection) Connector.open("file:///CFCard/newfile.txt");
// If no exception is thrown, then the URI is valid, but the file may or may not exist.
if (!fconn.exists()) fconn.create(); // create the file if it doesn't exist
OutputStream os = fconn.openOutputStream();
...
fconn.close();
关于java - 黑莓中的文件处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4195563/