AOS - Kotlin

[android/kotlin] base64 string > pdf 변환 후 파일 저장

야라라라 2024. 4. 5. 09:56
반응형
SMALL

base64 string을 pdf 파일로 변환 후 외부 저장소 앱 개별 공간에 저장

 

val fileName = "filename"
val base64Str = "testestestest"
try {
    val file = File(this.getExternalFilesDir(null) , fileName + ".pdf")
    val pdfAsBytes: ByteArray = Base64.decode(base64Str, 0)
    val os: FileOutputStream
    os = FileOutputStream(file, false)
    os.write(pdfAsBytes)
    os.flush()
    os.close()
}catch (e: java.lang.Exception){
}
반응형
LIST