Last active
April 7, 2020 00:28
-
-
Save weiancheng/aafdc03fe4bc0af931e934a71a023447 to your computer and use it in GitHub Desktop.
[Android Download] #android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val file = File(filePath) | |
val fileOutputStream = FileOutputStream(file) | |
val inputStream = BufferedInputStream(URL(url).openStream()) | |
var downloadSize = 0 | |
val buffer = ByteArray(bufferSize) | |
var bufferLength: Int | |
while (true) { | |
bufferLength = inputStream.read(buffer) | |
if (bufferLength <= 0) | |
break | |
fileOutputStream.write(buffer, 0, bufferLength) | |
downloadSize += bufferLength | |
} | |
fileOutputStream.flush() | |
fileOutputStream.close() | |
inputStream.close() | |
if (downloadSize != totalSize) { | |
Log.e(tag, "file was not complete") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val file = File(filePath) | |
val fileOutputStream = FileOutputStream(file) | |
val inputStream = BufferedInputStream(URL(url).openStream()) | |
var downloadSize = 0 | |
val buffer = ByteArray(bufferSize) | |
var bufferLength: Int | |
while (true) { | |
bufferLength = inputStream.read(buffer) | |
if (bufferLength <= 0) | |
break | |
fileOutputStream.write(buffer, 0, bufferLength) | |
downloadSize += bufferLength | |
} | |
fileOutputStream.flush() | |
fileOutputStream.close() | |
inputStream.close() | |
if (downloadSize != totalSize) { | |
Log.e(tag, "file was not complete") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment