I'm refactoring my project built with Java to Kotlin and to copy database from sqlite assets table I'm doing this and it works correctly.
private void copyDataBase() throws IOException {
InputStream mInput = mContext.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream mOutput = new FileOutputStream(outFileName);
byte[] mBuffer = new byte[1024];
int mLength;
while ((mLength = mInput.read(mBuffer)) > 0) {
mOutput.write(mBuffer, 0, mLength);
}
mOutput.flush();
mOutput.close();
mInput.close();
}
How do I deal with "Assignments are not expressions, and only expressions are allowed in this context"?
@Throws(IOException::class)
private fun copyDataBase() {
val mInput = mContext.assets.open(DB_NAME)
val outFileName = DB_PATH + DB_NAME
val mOutput = FileOutputStream(outFileName)
val mBuffer = ByteArray(1024)
var mLength: Int
while ((mLength = mInput.read(mBuffer)) > 0) {
mOutput.write(mBuffer, 0, mLength)
}
mOutput.flush()
mOutput.close()
mInput.close()
}
Error is here
while ((mLength = mInput.read(mBuffer)) > 0) {
mOutput.write(mBuffer, 0, mLength)
}
Thank you.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…