Java Utililty Methods URL Download nio

List of utility methods to do URL Download nio

Description

The list of methods to do URL Download nio are organized into topic(s).

Method

voiddownload(URL url, File out)
Copies the content of a URL to a local file.
ReadableByteChannel rbc = Channels.newChannel(url.openStream());
FileOutputStream fos = new FileOutputStream(out);
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
fos.close();
rbc.close();
Pathdownload(URL url, Path location)
download
try (final ReadableByteChannel channel = Channels.newChannel(url.openStream());
        final FileOutputStream outputStream = new FileOutputStream(location.toString())) {
    outputStream.getChannel().transferFrom(channel, 0, Long.MAX_VALUE);
    return location;
voiddownload(URL url, String save)
Downloads a file and saves it to a location on the computer
ReadableByteChannel channel = Channels.newChannel(url.openStream());
new FileOutputStream(save).getChannel().transferFrom(channel, 0, Long.MAX_VALUE);
voiddownloadAsync(String url, File file)
download Async
InputStream inputStream = new URL(url).openStream();
ReadableByteChannel rbc = Channels.newChannel(inputStream);
FileOutputStream fos = new FileOutputStream(file);
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
voiddownloadFile(final String url, final String downloadPath)
Download file.
URL website = new URL(url);
try (ReadableByteChannel rbc = Channels.newChannel(website.openStream())) {
    try (FileOutputStream fos = new FileOutputStream(downloadPath)) {
        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
FiledownloadFile(String fileName, String url)
Downloads file located at given url and saves it with given filename in the current directory.
final URL resourcesURL = new URL(url);
final ReadableByteChannel rbc = Channels.newChannel(resourcesURL.openStream());
FileOutputStream fos = new FileOutputStream(fileName);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
return new File(fileName);
StringdownloadFile(String fileURL, String folderPath)
Downloads the file with passed URL to the passed folder http://stackoverflow.com/a/921400/318221
int lastSlashPos = fileURL.lastIndexOf('/');
if (lastSlashPos < 0) {
    return null;
String fullFileName = folderPath + fileURL.substring(lastSlashPos + 1);
File file = new File(fullFileName);
file.getParentFile().mkdirs();
URL url;
...
PathdownloadFile(String inputUrl, String destination)
download File
String filename = Paths.get(inputUrl).getFileName().toString();
URL url;
try {
    url = new URL(inputUrl);
} catch (MalformedURLException e) {
    return null;
Path path;
...
voiddownloadFile(String sourceUrl, File destinationFile)
Download given URL into the destination file
URL website = new URL(sourceUrl);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destinationFile);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
voiddownloadFile(String url, File output)
Downloads a file from the specified URIL and saves it at the specified location.
final URL website = new URL(url);
final ReadableByteChannel rbc = Channels.newChannel(website.openStream());
final FileOutputStream fos = new FileOutputStream(output);
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
fos.close();