Привет, у меня большой bytesarray, и я хочу преобразовать в файл в SDCard, я использовал этот код, но cra sh иногда, что является лучшим способом для преобразования bytesarray в файл в kotlin?
private fun writeBytesToFileClassic(
bFile: ByteArray,
fileDest: String
) {
var fileOuputStream: FileOutputStream? = null
try {
fileOuputStream = FileOutputStream(fileDest)
fileOuputStream.write(bFile)
} catch (e: IOException) {
e.printStackTrace()
} finally {
if (fileOuputStream != null) {
try {
fileOuputStream.close()
} catch (e: IOException) {
e.printStackTrace()
}
}
}
}
fun ExtractPdf(byteArray: ByteArray, filename: String){
var fileInputStream: FileInputStream? = null
val file: File = File(UPLOAD_FOLDER())
if (!file.exists()){
file.mkdir()
}
try {
//save bytes[] into a file
writeBytesToFileClassic(byteArray, UPLOAD_FOLDER() + filename)
} catch (e: IOException) {
e.printStackTrace()
} finally {
if (fileInputStream != null) {
try {
fileInputStream.close()
} catch (e: IOException) {
e.printStackTrace()
}
}
}
}