Skip to content

Instantly share code, notes, and snippets.

@borsch
Created September 16, 2016 07:04
Show Gist options
  • Save borsch/69445bfb00a331be62b48d5012146965 to your computer and use it in GitHub Desktop.
Save borsch/69445bfb00a331be62b48d5012146965 to your computer and use it in GitHub Desktop.
down load file from url with java
String url = "http://my-site.com/text.txt";
String fileName = "/path/to/file/to/save/text.txt";
URL website = new URL(url);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(fileName);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment