Android(Kotlin)

SaveFile Android kotlin

----___<<<<< 2022. 5. 2. 03:17

fun saveLogAsFile(context: Context, saveText : String){

    Log.d("SDK LOG - SDKLoggingUtil : ", saveText)

    val randomUuid = UUID.randomUUID()

    val cFormat = SimpleDateFormat("hh:mm:ss")
    val currentDate = cFormat.format(Date())

    val file:String = currentDate
    val data:String = saveText
    val fileOutputStream: FileOutputStream
    try {
        fileOutputStream = context.openFileOutput("$file $randomUuid", Context.MODE_PRIVATE)
        fileOutputStream.write(data.toByteArray())
    } catch (e: FileNotFoundException){
        e.printStackTrace()
    }catch (e: NumberFormatException){
        e.printStackTrace()
    }catch (e: IOException){
        e.printStackTrace()
    }catch (e: Exception){
        e.printStackTrace()
    }

}