我願意做一個簡單的應用程序,根據這個entry將數據存儲在文本文件中,但我面臨一個令人沮喪的例外。BlackBerry:將文件保存到文本文件
這是我的代碼:
private boolean saveFile(String fileName, String fileContent) {
DataOutputStream os = null;
FileConnection fconn = null;
try {
fconn = (FileConnection)Connector.open(fileName,Connector.READ_WRITE);
if (!fconn.exists())
fconn.create();
os=fconn.openDataOutputStream();
String myString=fileContent;
os.write(myString.getBytes());
os.close();
fconn.close();
} catch (IOException e) {
// TODO Auto-generated catch block
Dialog.alert(e.toString());
return false;
}
return true;
}
private String getFileName() {
return "file:///SDCard/BlackBerry/documents/text.dat";
}
這是例外,我得到:
net.rim.device.api.io.file.FileIOException: File system error
的API說以下內容:
IOException - if the firewall disallows a connection that is not btspp or comm.
,我不知道可能有用或沒有。
我正在使用BlackBerry JRE 4.6.1和BlackBerry 8900 Simulator。 希望你們能幫助我。
哪一行是拋出異常?寫? – Tamar 2012-01-11 22:51:50
調試時發現'fileName'的值是什麼? – Rupak 2012-01-12 06:09:03
您的要求是保存文本文件,但在您提供「filename.dat」的getFileName()方法中。對於文本文件,它應該是「fileName.txt」。你有什麼例外? – alishaik786 2012-01-12 06:19:16