Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
p x
mycomutils
Commits
4bc32780
Commit
4bc32780
authored
Jan 23, 2026
by
p x
Browse files
添加assets 工具类
parent
5d52878c
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/commons/stand/FileAssetsIoUtils.kt
0 → 100644
View file @
4bc32780
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
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment