Created
April 9, 2010 13:18
-
-
Save jimbojw/361148 to your computer and use it in GitHub Desktop.
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
var | |
// path to something you want to download | |
path = "http://something/you/want/to/download", | |
// file you want to save it as | |
file = new java.io.File( "path/to/somewhere/local" ), | |
// create URL object and establish connection | |
url = new java.net.URL(path), | |
conn = url.openConnection(), | |
// input and output streams | |
bis = new java.io.BufferedInputStream(conn.inputStream), | |
out = new java.io.BufferedOutputStream( | |
new java.io.FileOutputStream(file) | |
), | |
// buffer to hold next read chunk and number of bytes read in chunk | |
buf = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 4096), | |
n = 0; | |
// read bytes until end of input, writing to buffer | |
while ((n = bis.read(buf, 0, buf.length)) != -1) { | |
out.write(buf, 0, n); | |
} | |
// flush output and close streams | |
out.flush(); | |
bis.close(); | |
out.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment