Advertisement
Guest User

Untitled

a guest
May 30th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. fun testGetFile(contentUri: String) : File? {
  2. val file = File(cacheDir, "img_${System.currentTimeMillis()}")
  3.  
  4. try {
  5. file.createNewFile()
  6. } catch (ex: IOException) {
  7. Log.e("debug", "Error while file creation", ex)
  8. return file
  9. }
  10.  
  11. val inputStream = contentResolver.openInputStream(Uri.parse(contentUri))
  12. val bytearray = inputStream.readBytes()
  13.  
  14. val outputStream = FileOutputStream(file)
  15. outputStream.write(bytearray)
  16.  
  17. return file
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement