There is an online file (such as http://www.example.com/information.asp
) I need to grab and save to a directory. I know there are several methods for grabbing a
This is another java7 variant based on Brian Risk's answer with usage of try-with statement:
public static void downloadFileFromURL(String urlString, File destination) throws Throwable {
URL website = new URL(urlString);
try(
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
){
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
}
}