I am downloading a pdf file from a web server using okhttp. The file appears to download correctly, and the file "Test.pdf" is created. The file size is listed as 0 however in the Device File Explorer in Android Studio.
Here is my callback code:
client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
println("Failed")
}
override fun onResponse(call: Call, response: Response) {
println("Success!")
val file = File(filesDir, "Test.pdf")
println(response.body()!!.bytes().size)
file.outputStream().write(response.body()!!.bytes())
file.outputStream().flush()
file.outputStream().close()
}
})
The println statement shows the correct file size of 6MB. I am really unsure why the file is not writing to the device.