Last active
February 28, 2023 21:16
-
-
Save afkvido/ff65086bc60e606ef6a00f86ef6316c6 to your computer and use it in GitHub Desktop.
Read data from URL in Kotlin.
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
import java.net.URI | |
import java.net.URL | |
import java.util.* | |
/** Get text from an online resource */ | |
fun fetch (url : URL) : String { | |
println("Fetching resource from $url") | |
return Scanner(url.openStream(), "UTF-8").useDelimiter("\\A").next() | |
} | |
fun fetch (url : String) : String { | |
return fetch(URL(url)) | |
} | |
fun fetch (url : URI) : String { | |
return fetch(url.toURL()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment