2010-11-16 80 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