Skip to content

Instantly share code, notes, and snippets.

@antoni
Created April 13, 2016 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antoni/a914722b6550bd5e6a7473f163283371 to your computer and use it in GitHub Desktop.
Save antoni/a914722b6550bd5e6a7473f163283371 to your computer and use it in GitHub Desktop.
Download file using Java NIO
URL website = new URL(FILE_URL);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(TMP_FILE_NAME);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment