2010-11-16 90 views
1

我正在重复使用一些android代码到我的黑莓应用程序中。有一行代码这样黑莓文件处理

File f = new File(cacheDir, filename); 

其中cacheDir是一个文件&文件名是一个字符串。 但在黑莓实现此同一行,当我得到错误

“的构造文件(文件,字符串)是 未定义”。

任何人都可以帮助我。

UPDATE

其中我面临的另一个误差是该线

OutputStream os = new FileOutputStream(f); 

其中f是FileConenction流的实例。错误说

“的构造 FileOutputStream中(的FileConnection)是 未定义”

谁能帮助?

+0

嗨!您随时可以编辑您的问题以添加新的信息,以便将来重复使用您的问题将更为容易。 – 2010-11-16 16:06:42

回答

1

你必须使用

Connector.open("file://" + dirName); 

更多信息可here

你可以试试这个:

OutputConnection connection = (OutputConnection)      
    Connector.open("file://c:/myfile.txt;append=true", Connector.WRITE); 
OutputStream out = connection.openOutputStream(); 
PrintStream output = new PrintStream(out); 

output.println("This is a test."); 

out.close(); 
connection.close(); 

here

+0

非常感谢你 – 2010-11-16 15:27:25

+0

我正面临的另一个错误是这条线 – 2010-11-16 15:33:53

+0

OutputStream os = new FileOutputStream(f);其中f是实例os FileConenction流。错误说“构造函数FileOutputStream(FileConnection)未定义” – 2010-11-16 15:34:52

2

平时采取Java API在BB上不起作用。

请参阅javax.microedition.io.Connectorjavax.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(); 
+0

非常感谢 – 2010-11-16 17:58:26