Skip to content

Instantly share code, notes, and snippets.

@LongClipeus
Last active September 27, 2021 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LongClipeus/c17abc291acb884da9aefeec6b5b9da9 to your computer and use it in GitHub Desktop.
Save LongClipeus/c17abc291acb884da9aefeec6b5b9da9 to your computer and use it in GitHub Desktop.
import android.content.Context
import androidx.annotation.RawRes
import com.tech.melait.common.utils.ResourceUtils.readRawFile
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
suspend fun readRawFile(context: Context, @RawRes res: Int) = withContext(Dispatchers.Default) {
context.resources.readRawFile(res)
}
fun Resources.readRawFile(@RawRes rawResId: Int): String {
return openRawResource(rawResId).bufferedReader().use { it.readText() }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment