private fun copyDatabase(context: Context): Boolean {
try {
val inputStream = context.assets.open(DatabaseHelper.DBNAME)
val outFileName = DatabaseHelper.DBLOCATION + DatabaseHelper.DBNAME
val outputStream = FileOutputStream(outFileName)
val buff = ByteArray(1024)
var length = 0
while((length = inputStream.read(buff)) > 0) {
outputStream.write(buff , 0 , length)
}
outputStream.flush()
outputStream.close()
Log.w("MainActivity" , "DB copied")
return true
} catch (e: Exception) {
e.printStackTrace()
return false
}
}
此代码中的“虽然”无法正常工作,我需要帮助
答案 0 :(得分:1)
您似乎正在尝试将InputStream内容复制到OutputStream。为此,您可以在Kotlin中使用InputStream.copyTo
扩展功能:
select * from my_table m
inner join (
select column1, max(column3) col3
from my_table
group by column1
) t on t. column1 = m.column1 and t.col3 = m.column3
答案 1 :(得分:1)
您可以这样解决:
...
var length = inputStream.read(buff)
while(length > 0) {
outputStream.write(buff , 0 , length)
length = inputStream.read(buff)
}
...
但是@Ilya是对的,您在Kotlin的土地上,最好使用Kotlin提供的工具