我正在为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异常
fc = (FileConnection)Connector.open("file:///store/home/user/HabbleLog.txt");
有人知道为什么吗?我必须考虑fs差异吗? 感谢。