Created
June 18, 2015 14:02
-
-
Save memememomo/24ef4b01fd64fa37deba to your computer and use it in GitHub Desktop.
画像ファイルをダウンロードして保存する ref: http://qiita.com/uchiko/items/105829eb9b91843c0077
This file contains hidden or 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.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