Issue
Is there any kotlin idiomatic way to read a file content's asynchronously? I couldn't find anything in documentation.
Solution
Here's how to do it with coroutines:
launch {
val contents = withContext(Dispatchers.IO) {
FileInputStream("filename.txt").use { it.readBytes() }
}
processContents(contents)
}
go_on_with_other_stuff_while_file_is_loading()
Answered By - Marko Topolnik
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.