gpt4 book ai didi

android - 赋值不是表达式 - Kotlin

转载 作者:搜寻专家 更新时间:2023-11-01 09:24:56 24 4
gpt4 key购买 nike

我正在将我用 Java 构建的项目重构为 Kotlin,并从 sqlite Assets 表复制数据库我正在这样做,它工作正常。

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();
}

如何处理“赋值不是表达式,在此上下文中只允许使用表达式”?

@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()
}

错误在这里

while ((mLength = mInput.read(mBuffer)) > 0) {
mOutput.write(mBuffer, 0, mLength)
}

谢谢。

最佳答案

将其更改为:

 mLength = mInput.read(mBuffer)
while (mLength > 0) {
mOutput.write(mBuffer, 0, mLength)
mLength = mInput.read(mBuffer)
}

关于android - 赋值不是表达式 - Kotlin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51399793/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com