Last active
January 2, 2018 06:28
-
-
Save nguyenlinhnttu/af25a265968af7372afc379a112c6a3c to your computer and use it in GitHub Desktop.
SQLite Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SqlHelper(var mContext: Context) { | |
val DB_NAME: String = "essays_eng.db" | |
fun openDataBase(): SQLiteDatabase { | |
val dbFile : File = mContext.getDatabasePath(DB_NAME) | |
if (!dbFile.exists()) { | |
val dir = dbFile.parentFile | |
dir.mkdirs() | |
mContext.assets.open(DB_NAME).use { input -> dbFile.outputStream().buffered().use { output -> | |
input.copyTo(output, 10240 ) | |
} | |
} | |
} | |
return SQLiteDatabase.openDatabase(dbFile.path, null, SQLiteDatabase.OPEN_READWRITE) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should use FIRST START APP. IF database bug size please set delay time.