Skip to content

Instantly share code, notes, and snippets.

@memememomo
Created June 18, 2015 14:02
Show Gist options
  • Save memememomo/24ef4b01fd64fa37deba to your computer and use it in GitHub Desktop.
Save memememomo/24ef4b01fd64fa37deba to your computer and use it in GitHub Desktop.
画像ファイルをダウンロードして保存する ref: http://qiita.com/uchiko/items/105829eb9b91843c0077
import java.io.{FileOutputStream, BufferedOutputStream}
import java.net.URL
import scala.language.postfixOps
object Main {
def main(args: Array[String]) = {
val image_url = "http://pic.prepics-cdn.com/fuualbum0408/19574639.jpeg"
val file_name = "hato.jpg"
download(image_url, file_name)
}
def download(url: String, file_name: String) = {
val stream = new URL(url).openStream
val buf = Stream.continually(stream.read).takeWhile( -1 != ).map(_.byteValue).toArray
val bw = new BufferedOutputStream(new FileOutputStream(file_name))
bw.write(buf)
bw.close
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment