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

voiddownloadFromHttpUrl(String destPkgUrl, FileOutputStream outputStream)
download From Http Url
URL website = new URL(destPkgUrl);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
outputStream.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
voiddownloadFromInternet(URL url, File downloadTo)
download From Internet
ReadableByteChannel rbc = null;
FileOutputStream fos = null;
try {
    rbc = Channels.newChannel(url.openStream());
    fos = new FileOutputStream(downloadTo);
    fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
} finally {
    closeQuietly(rbc);
...
PathdownloadImage(String src, Path saveFolder)
download Image
Path saveFilePath = srcImageToSavePath(src, saveFolder);
URL url = new URL(src);
try (InputStream in = url.openStream(); OutputStream out = Files.newOutputStream(saveFilePath)) {
    for (int b; (b = in.read()) != -1;) {
        out.write(b);
return saveFilePath;
...
voiddownloadToFile(String filename, String urlString)
Downloads data from the given URL and saves it to the given file
downloadToFile(new URL(urlString), new File(filename));
voiddownloadToFile(URL url, File file)
download To File
file.getParentFile().mkdirs();
ReadableByteChannel rbc = Channels.newChannel(url.openStream());
FileOutputStream fos = new FileOutputStream(file);
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
fos.close();
StringdownloadToString(String url)
download To String
InputStream inputStream = openStream(url);
if (inputStream == null) {
    return null;
return new String(streamToByteArray(inputStream), Charset.forName("UTF-8"));
booleandownloadUrl(String urlstring, File file)
download Url
try {
    URL url = new URL(urlstring);
    ReadableByteChannel rbc = Channels.newChannel(url.openStream());
    FileOutputStream fos = new FileOutputStream(file);
    fos.getChannel().transferFrom(rbc, 0, 1 << 24);
    return true;
} catch (Exception e) {
    e.printStackTrace();
...