【发布时间】:2018-05-05 18:27:08
【问题描述】:
我正在使用 okhttp 从 Web 服务器下载 pdf 文件。该文件似乎可以正确下载,并创建文件“Test.pdf”。文件大小在 Android Studio 的设备文件资源管理器中列为 0。
这是我的回调代码:
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()
}
})
println 语句显示正确的文件大小为 6MB。我真的不确定为什么文件没有写入设备。
【问题讨论】:
标签: io kotlin okhttp android-file