protected void del(){
Context context = getApplicationContext();
String databasePath = context.getDatabasePath("数据库名称.db").getPath();
// 关闭数据库连接
SQLiteDatabase database = SQLiteDatabase.openDatabase(databasePath, null, SQLiteDatabase.OPEN_READWRITE);
database.close();
// 删除数据库文件
File databaseFile = new File(databasePath);
if (databaseFile.exists()) {
boolean deleted = databaseFile.delete();
if (deleted) {
System.out.println("成功删除");
} else {
System.out.println("成功删除");
}
} else {
System.out.println("不存在");
}
}
Android Studio 删除数据库
于 2024-01-05 13:41:22 首次发布