Java Utililty Methods URL Download

List of utility methods to do URL Download

Description

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

Method

booleandownImg(String filePath, String imageUrl, String fileName)
down Img
try {
    File files = new File(filePath);
    if (!files.exists()) {
        files.mkdirs();
    URL url = new URL(imageUrl);
    URLConnection con = url.openConnection();
    InputStream is = con.getInputStream();
...
Stringdownload(final String sURL, final String sFilename)
Download a file at a remote URL to the local disk or to the memory.
final URL u = new URL(sURL);
final URLConnection conn = u.openConnection();
final InputStream is = conn.getInputStream();
final byte[] buff = new byte[10240];
int read;
final OutputStream os;
String actualFileName = sFilename;
if (sFilename != null) {
...
byte[]download(final URL url)
Will download file data ready to be exported to a file
return readData(url.openStream());
voiddownload(String downloadUrlStr, String filename)
download data from url.
File downloadDir = new File(new File(".", "download").getAbsolutePath());
if (!downloadDir.exists()) {
    downloadDir.mkdirs();
File filepath = new File(downloadDir, filename);
System.out.println("------------------------------------");
System.out.println("Start download.");
System.out.println("DOWNLOAD_URL  = " + downloadUrlStr);
...
voiddownload(String fileUrl, String savePath, String fileName)
download
OutputStream out = null;
DataInputStream input = null;
try {
    File directory = new File(savePath);
    if (!directory.exists() && !directory.isDirectory()) {
        directory.mkdirs();
    if (!checkFileExists(fileUrl)) {
...
byte[]download(String url)
download
final ByteArrayOutputStream result = new ByteArrayOutputStream();
try (InputStream is = new URL(url).openStream()) {
    copy(is, result);
return result.toByteArray();
voiddownload(String url, String path)
download
InputStream is = null;
OutputStream os = null;
try {
    is = new URL(url).openStream();
    byte[] bs = new byte[1024];
    int len;
    os = new FileOutputStream(path);
    while ((len = is.read(bs)) != -1) {
...
booleandownload(String url, String saveFile)
download
try {
    int readCount = 0;
    byte[] buffer = new byte[1204];
    InputStream inputStream = new URL(url).openConnection().getInputStream();
    FileOutputStream fs = new FileOutputStream(saveFile);
    while ((readCount = inputStream.read(buffer)) != -1) {
        fs.write(buffer, 0, readCount);
    return true;
} catch (FileNotFoundException e) {
    return false;
} catch (IOException e) {
    return false;
voiddownload(String url, String toFile)
download
log.log(Level.INFO, "Downloading {0} ...", url);
long startTime = System.currentTimeMillis();
URL intUrl = new URL(url);
intUrl.openConnection();
InputStream reader = intUrl.openStream();
FileOutputStream writer = new FileOutputStream(toFile);
try {
    byte[] buffer = new byte[BUFFER];
...
voiddownload(String urlAddress, File file)
download
file.getParentFile().mkdirs();
try {
    OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
    InputStream inputStream = new URL(urlAddress).openConnection().getInputStream();
    byte[] data = new byte[2048];
    int read = 0;
    while ((read = inputStream.read(data)) != -1) {
        outputStream.write(data, 0, read);
...