Solved

Java program to download files from the internet

Posted on 2006-06-10
2
176 Views
Last Modified: 2010-03-31
I need to write a java program that can download files from the internet,can anybody help me with how to go about it,any reading material or pieces of code that wud make me understand how to do it and what technology do i use.also can somebody write one such program and post it here,thanks in advance.
0
Comment
Question by:venban
2 Comments
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 16876375
Give the URL of your file in the internet in the String. the result will be stored in result. If you know the type of file you are getting eg., .doc or .pdf give the extension to the file name.

                          String str = "Your File URL" ;
               URL url = new URL ( str ) ;
            
                  URLConnection connect  = url.openConnection() ;
            
                FileOutputStream out = new FileOutputStream ( "result" ) ;
BufferedInputStream input = new BufferedInputStream ( connect .getInputStream() ) ;
            
            int ret = -1 ;
            
            while ( (ret = input.read() ) != -1 )
            {
                  out.write( ret ) ;
            }
            
            out.close() ;
            input.close() ;

Cheers,
Mukundh
0
 
LVL 26

Accepted Solution

by:
ksivananth earned 500 total points
ID: 16876487
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
session migration servlets 2 36
Java exception bubble up 2 18
servlet example 17 32
maven module vs maven project 3 23
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question