Solved

Java program to download files from the internet

Posted on 2006-06-10
2
171 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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…
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.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now