package com.sd.geelyhmiweb.utils

import android.os.Environment
import android.util.Log
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.File
import java.io.FileWriter
import java.io.IOException


object FileIoUtils {

    private var fileWriter: FileWriter? = null
    suspend fun writeToFile(message: String, fileName: String) {
//        if (MyContants.WRITE_LOG){
            withContext(Dispatchers.IO) {
                try {
                    val file = File(
                        Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
                        fileName
                    )
                    fileWriter = FileWriter(file, true) // true for append mode
                    fileWriter!!.append("$message\n")
                    fileWriter!!.flush() // Optional, to ensure immediate writing to file
                } catch (e: IOException) {
                    Log.e("------writeToFile", "Error initializing log file", e)
                }
            }
//        }
    }



}