0
我想打开资源文件。在java代码工作之前,但当我将代码更改为kotlin时,它不起作用。Android的开放科特林资源文件
Java代码的工作
InputStream streamIN = new BufferedInputStream(context.getAssets().open(Database.ASSET));
OutputStream streamOU = new BufferedOutputStream(new FileOutputStream(LOCATION));
byte[] buffer = new byte[1024];
int length;
while ((length = streamIN.read(buffer)) > 0) {
streamOU.write(buffer, 0, length);
}
streamIN.close();
streamOU.flush();
streamOU.close();
我更改代码科特林但它不工作
var length: Int
val buffer = ByteArray(1024)
BufferedOutputStream(FileOutputStream(LOCATION)).use {
out ->
{
BufferedInputStream(context.assets.open(Database.ASSET)).use {
length = it.read(buffer)
if (length > 0) out.write(buffer, 0, length)
}
out.flush()
}
}
什么并不完全工作?任何例外? – Mibac
没有例外。当我调试我的应用程序,调试器是不是在lambda函数(的BufferedOutputStream) – kibar