5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

画像ファイルをダウンロードして保存する

Posted at
Downloader.scala
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
  }
}
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?