package commons.stand import android.content.Context import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import java.io.InputStream /*****、获取assets文件内容*****/ object FileAssetsIoUtils { suspend fun getFileDate(context: Context, fileName: String): String { return withContext(Dispatchers.IO){ val assetManager = context.assets val inputStream: InputStream = assetManager.open(fileName) // 方式1:手动逐行读取(推荐,Kotlin简洁写法) val ret= inputStream.use { ins -> // use 自动关闭流(AutoCloseable) val size = ins.available() val bytes = ByteArray(size) ins.read(bytes) val str = String(bytes) return@use str } return@withContext ret } } }