Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //file utils
- import android.util.Log
- import java.io.BufferedReader
- import java.io.IOException
- import java.io.InputStreamReader
- import java.nio.Buffer
- object FileUtils {
- const val TAG: String = "FILE_UTILS_TAG"
- fun readTextFromRaw(context: Context, resId: Int): String{
- var bufferReader: BufferedReader? = null
- return try {
- val inputStream = context.resources.openRawResource(resId)
- val bufferedReader = BufferedReader(InputStreamReader(inputStream))
- var lines: String? = null
- lines = bufferedReader.readText()
- lines
- } catch (e: Exception){
- when(e){
- is IOException -> {e.printStackTrace(); ""}
- is Resources.NotFoundException -> {e.printStackTrace(); ""}
- else -> {""}
- }
- } finally {
- bufferReader?.close()
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement