Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val conexion: HttpsURLConnection
- val urlArchivo: URL
- val url1 = "Mi URL"
- val fileOut: FileOutputStream
- val buffersize = 1024
- val buffer: ByteArray
- try {
- urlArchivo = URL(url1)
- conexion = urlArchivo.openConnection() as HttpsURLConnection
- conexion.readTimeout = 1000
- conexion.connectTimeout = 1000
- conexion.doInput = true
- conexion.requestMethod = "GET"
- conexion.connect()
- ruta = conexion.inputStream
- fileOut = FileOutputStream(archivo) // ubicacion archivo
- var bytesEscribir: Int
- buffer = ByteArray(buffersize)
- while ((bytesEscribir = ruta.read(buffer)) > 0) {
- fileOut.write(buffer, 0, bytesEscribir)
- }
- Toast.makeText(activity!!.applicationContext, getString(R.string.sinc_exitosa), Toast.LENGTH_LONG).show()
- ruta.close()
- fileOut.close()
- conexion.disconnect()
Add Comment
Please, Sign In to add comment