Download a url file into desktop. For example, download image file (gif, jpg) using java and apache commons io api
Tech-Today

Download a url file into desktop. For example, download image file (gif, jpg) using java and apache commons io api


To make this code works you need:
1.) http://commons.apache.org/io/download_io.cgi
2.) make sure to configure your build path and include the apache commons io jar (I've used eclipse-java ide)
3.) the url that will be save are stored in the input/input.txt file, sample input file:
[input.txt]
http://google.com/file1.jpg
http://google.com/file2.jpg
http://google.com/file3.jpg
[/input.txt]


package org.ipiel.tools.friendster.downloader;

import java.io.*;
import java.net.URL;

import org.apache.commons.io.FileUtils;

public class PhotoDownloader {
public static void main(String args[]) {
new PhotoDownloader();
}

public PhotoDownloader() {
try {
BufferedReader lineReader = new BufferedReader(new FileReader("input/input.txt"));
String line = "";
int ctr = 1;

while((line = lineReader.readLine()) != null) {
URL u = new URL(line);
String output = line.substring(line.lastIndexOf('/') + 1);
System.out.println((ctr++) + " Downloading: " + output);
FileUtils.copyURLToFile(u, new File(output));
}

} catch(IOException e) {
e.printStackTrace();
}
}
}


One piece of advice, don't try creating your own class :-D, it's already done :-D. Thanks to the apache boys they always make my code simple :-D

Well you might ask, how can I do this in C#?
Read this link http://czetsuya-tech.blogspot.com/2010/03/download-image-given-url-in-c-using.html




- Hadoop Mapreduce Demo
Versions: Hadoop 3.1.1 Java10Set the following environment variables: JAVA_HOME HADOOP_HOMEFor WindowsDownload Hadoop 3.1.1 binaries for windows at https://github.com/s911415/apache-hadoop-3.1.0-winutils. Extract in HADOOP_HOME\bin and make...

- Encode Image And Display In Html
To encode an image file(eg. png, jpg, gif) we will need the apache commons-codec library. To avoid it in a maven project: <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.11</version>...

- How To Encode And Decode A Json Encrypted String In Java
This tutorial requires the use of apache commons and jackson libraries. For example I have a highly confidential string and I want to send it over the net, of course normally I want to encrypt it. And one of the method we can send this encrypted string...

- Html Scraping With Java
One rainy Sunday afternoon since I can't get out to go somewhere I've decided to create an organized excel file (for now) for the list of birds commonly found in the Philippines. I found a good site to start with, http://www.birding2asia.com/tours/reports/PhilFeb2010_list.html,...

- Download Image Given A Url In C# Using The System.net.httpwebrequest Class
Saves image url object into the local machine /// /// Saves the list of url object into the output directory /// /// list of url path /// root directory that will be used for saving internal static void PhotoDownloader(ArrayList aList, string outputDir)...



Tech-Today








.