Guest User

Untitled

a guest
Jan 11th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. val conexion: HttpsURLConnection
  2. val urlArchivo: URL
  3. val url1 = "Mi URL"
  4. val fileOut: FileOutputStream
  5. val buffersize = 1024
  6. val buffer: ByteArray
  7.  
  8. try {
  9. urlArchivo = URL(url1)
  10. conexion = urlArchivo.openConnection() as HttpsURLConnection
  11. conexion.readTimeout = 1000
  12. conexion.connectTimeout = 1000
  13. conexion.doInput = true
  14. conexion.requestMethod = "GET"
  15. conexion.connect()
  16.  
  17. ruta = conexion.inputStream
  18. fileOut = FileOutputStream(archivo) // ubicacion archivo
  19.  
  20. var bytesEscribir: Int
  21. buffer = ByteArray(buffersize)
  22.  
  23. while ((bytesEscribir = ruta.read(buffer)) > 0) {
  24.  
  25. fileOut.write(buffer, 0, bytesEscribir)
  26. }
  27. Toast.makeText(activity!!.applicationContext, getString(R.string.sinc_exitosa), Toast.LENGTH_LONG).show()
  28. ruta.close()
  29. fileOut.close()
  30. conexion.disconnect()
Add Comment
Please, Sign In to add comment