我要用Kotlin / Android编写一个小应用程序,ich希望从Api中执行下载任务,但是该站点很长,而且下载要花很多时间,我如何限制下载大小?例如,仅从API的第一个Json Objekts起
fun downloadData (address : String) :String{
var result = ""
var url : URL
var urlConnection : HttpURLConnection?
url = URL(address)
urlConnection = url.openConnection() as HttpURLConnection
val input = urlConnection.getInputStream()
val reader = InputStreamReader(input)
var data = reader.read()
while (data != -1) {
val current = data.toChar()
result += current
data = reader.read()
}
return result
}