我正在为 BB 构建一个应用程序,并创建了一个类来将一些日志存储在手机上的文件中。这是我的代码:
public class Logger {
public static void trace(String line) {
FileConnection fc = null;
OutputStream outStream = null;
if (ApplicationConstant.DEBUG_ENABLED) {
try {
fc = (FileConnection)Connector.open("file:///store/home/user/HabbleLog.txt");
if (!fc.exists()) fc.create(); // create the file if it doesn't exist
outStream = fc.openOutputStream(fc.fileSize());
outStream.write((line + "\n").getBytes());
System.out.println(line);
} catch (Exception ioe) {
System.out.println(ioe.toString());
} finally {
try {
outStream.close();
fc.close();
} catch (IOException ex) {
ex.toString();
}
}
}
}
}
它在 Bold 9700 上运行良好,但是当我在 Bold 9900 上运行应用程序时,我得到一个 NullPointer Exception 就行了
fc = (FileConnection)Connector.open("file:///store/home/user/HabbleLog.txt");
有人知道为什么吗?是否有我必须考虑的 fs 差异?谢谢。