Wie zum download und speichern Sie eine Datei aus dem internet mit Scala?

Grundsätzlich habe ich eine url/link zu einer text-Datei online und ich bin versucht, es herunterzuladen lokal. Für einige Grund, die text-Datei wird erstellt/heruntergeladen leer ist. Offen für alle Vorschläge. Danke!

    def downloadFile(token: String, fileToDownload: String) {

    val url = new URL("http://randomwebsite.com/docs?t=" + token + "&p=tsr%2F" + fileToDownload)
    val connection = url.openConnection().asInstanceOf[HttpURLConnection]
    connection.setRequestMethod("GET")
    val in: InputStream = connection.getInputStream
    val fileToDownloadAs = new java.io.File("src/test/resources/testingUpload1.txt")
    val out: OutputStream = new BufferedOutputStream(new FileOutputStream(fileToDownloadAs))
    val byteArray = Stream.continually(in.read).takeWhile(-1 !=).map(_.toByte).toArray
    out.write(byteArray)
    }
InformationsquelleAutor slizorn | 2014-06-11
Schreibe einen Kommentar