Created
September 16, 2016 07:04
-
-
Save borsch/69445bfb00a331be62b48d5012146965 to your computer and use it in GitHub Desktop.
down load file from url with java
This file contains 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
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