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