【发布时间】:2011-03-29 21:53:32
【问题描述】:
我正在构建一个 Blackberry 应用程序,在该应用程序启动时创建一个数据库。问题是代码在 sdCard 上运行良好,但是当我删除 SDCard 并尝试使用 Phone Memory 时,它不起作用。 这是我用来创建数据库的代码:
public static String db_location="file:///SDCard/Databases/MyApp/MyDatabase.db";
public MyDatabase() {
// TODO Auto-generated constructor stub
boolean sdCardPresent = false;
String root = null;
Enumeration e = FileSystemRegistry.listRoots();
while (e.hasMoreElements())
{
root = (String)e.nextElement();
if(root.equalsIgnoreCase("sdcard/"))
{
sdCardPresent = true;
}
}
if(!sdCardPresent)
{
// If an SDCard is not available we will store our database in
// flash memory. This is not recommended for large databases.
db_location = "file:///store/home/user/Databases/MyApp/MyDatabase.db";
}
try
{
URI myURI = URI.create(db_location);
d = DatabaseFactory.create(myURI);
d.close();
}
catch ( Exception e1 )
{
System.out.println( e1.getMessage() );
e1.printStackTrace();
}
}
请推荐
【问题讨论】:
标签: blackberry blackberry-simulator