Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

URL file Download and Save in the Local Directory

                         

This Program file download  from  URL and save this Url File in the specified directory. This program specifies the directory path where the files to be stored  as first command line argument and second command line arguments specifies URL File to be stored. Java creates link between Url and Java application.Using the openConnection() method creates URLConnection object. This connection  read the data using InputStream and FileOutputStream write the data to the local file in a specified directory.



                                                                                                                     
Source Code : "UrlDownload.java"
       

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

public class UrlDownload {
final static int size=1024;
public static void
fileUrl(String fAddress, String
localFileName, String destinationDir) {
OutputStream outStream = null;
URLConnection  uCon = null;

InputStream is = null;
try {
URL Url;
byte[] buf;
int ByteRead,ByteWritten=0;
Url= new URL(fAddress);
outStream = new BufferedOutputStream(new
FileOutputStream(destinationDir+"\\"+localFileName));

uCon = Url.openConnection();
is = uCon.getInputStream();
buf = new byte[size];
while ((ByteRead = is.read(buf)) != -1) {
outStream.write(buf, 0, ByteRead);
ByteWritten += ByteRead;
}
System.out.println("Downloaded Successfully.");
System.out.println("File name:\""+localFileName+ "\"\nNo ofbytes :" + ByteWritten);
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
is.close();
outStream.close();
}
catch (IOException e) {
e.printStackTrace();
}}}
public static void fileDownload(String fAddress, String destinationDir)
{
 
  int slashIndex =fAddress.lastIndexOf('/');
int periodIndex =fAddress.lastIndexOf('.');

String fileName=fAddress.substring(slashIndex + 1);

if (periodIndex >=&&  slashIndex >= && slashIndex < fAddress.length()-1)
{
fileUrl(fAddress,fileName,destinationDir);
}
else
{
System.err.println("path or file name.");
}}
public static void main(String[] args)
{

if(args.length==2)
{
for (int i = 1; i < args.length; i++) {
fileDownload(args[i],args[0]);
}
}
else{
  
}
}
}

                                        


Download the application

 

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
Murach�°�?�°???s
struts2 sql tag
bubble sort
UMLGraph - Declarative
jsp tags
linked list exception
web spear
FIFO
Listeners
JSP:File Input Paramet
Photoshop Refrozen Eff
breakÑ?Ð??Ñ?Ð???Ñ?Ð???
ASP Form Processing Se
breakÑ????Ñ??Ð?Ñ??Ð???
<sql-query>
à¹?à¸?à¸?à¹???à¹?à¸?à¸
break?аÐ?а????????а
how to use swing
loading combo values f
resultset
connect a program writ
calculating prime numb
add in excel
ASP Form Processing Se
ASP Form Processing Se
struts _ Deleting the
how to hide a select t
BLAG Linux and GNU 300
C and Cpp Programming
navigate to other page
Integer.ParseInt examp
get column count
commons.validator
jstl
Murachะ�?ะ�???
html tables
?ä»??é?«?é?«???ä»??é?«
JTable size
ä»??é?«?é?«?ä»??é?«???
input charaters in arr
Button
timeline using javascr
Photoshop Textures and
Statement
images,video jsp
drop
ospf
iterator excel sheet
UML basics: The compon
www.youtube.com
how to print arraylist
Declaring java technol
JDBC with Mysql in Ecl
lire
Photoshop Text Effects
ร?ย  in struts
ASP Ad Management Rota
charts using POI
integer to month
sequence number genera
<select
newline character
java program for permu
Refresh a Web Page Usi
eclipse online tutoria
jsf and database manip
Sort column Header on
Refresh a Web Page Usi
what is rfc ?
cashier
J2ME and WAP
enumerations
java source code for c
delete statement form
jsp standard tags
drow rectangular
what is rfc
filereader
strutstext field and
distributed transactio
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.