Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Java program to download files from the internet

Posted on 2006-06-10
2
Medium Priority
?
190 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 2000 total points
ID: 16876487
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Suggested Courses

971 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