Downloading a file in Java

Hello,
I would like to write a Java application to download some files from the Internet.
I have a basic understanding of Sockets with Perl. However, I have not done this in Java.
I would like to connect to a file on the Internet via a Socket and copy the file to my local machine.
I have browsed for tutorials on the Internet but have not found anything dealing with this (as mostly all information deals with downloading the JVM and such).
I can code it myself as I am not looking for a solution. However, I am looking for some basic pointers to get started. I was hoping someone could give me a list of classes I would need, a few urls to some nice tutorials or even some very basic code examples. Again, I just need to be pointed in the right direction to get started.
Thank you in advance!
Cheers,
Chris

Wouldnt it be possible for example "protect" the
server using username and password? For example the
URL could be:
http:\\www.mywebsite.com\my_upload_page.html?password=m
password&username=myusername
or something like that??Sure; but instead of passing clear-text usernames and passwords on the URL, the usual convention is to use encrypted authentication (ranging from BASIC authentication to CERTIFICATE authentication, where the authentication is put into the HTTP request body and encrypted at some level). But it of course still requires that the server be running some special servlet/application to accept the upload requests (hence the servlet/FTP hint).
That's all I'm going to say about it; it can be far too much a topic for discussion here and I don't want to spend all that much time on it.

Similar Messages

  • Downloading a File with Java

    Hi
    My application downloads a file from a
    website.
    The problem I am having is that if no internet connection is present the
    program throws an exception to do with "Unable to resolve Inet Address".
    If there is an internet connection present it works fine.
    The behaviour I would like (and indeed had until I upgraded to WInXp
    Pro) is for the application to prompt the user to connect to the
    internet if no connection is present.
    I have been unable to locate a method in Java that checks whether an
    internet connection is present of not.
    I am unsure whether the problem is with the setup of the operating
    system or with my code, but if Internet Explorer or Outlook are loaded
    with no internet connection present then a prompt to connect to the web
    is displayed.
    Any help would be much appreciated
    Thanks

    dear friend
    u can do like this.
    try {
    //put your statement here
    } catch(<TheException that is thrown>)
    System.ot.println("connection to internet is not present");
    next part of code
    u can also use a finally block if u want that a
    statement must be executed.hope u know syntax for that.
    regards
    sheetal

  • ITS - upload/download of files - getting java error on download

    Hi, I'm working on ITS to upload/download some files, really simple files in ASC and i use cl_gui_frontend_services=>gui_upload it works fine, and to download the cl_gui_frontend_services=>gui_download that in R/3 works but on the ITS give an error.
    Any idea or someone that happend the same?
    Thanks in advance to all
    Regards
    Jaime

    there is a dedicated ITS forum at Internet Transaction Server (ITS)
    search that forum, this has been discussed may times.
    Raja

  • How to download video files using java

    hi,
    i am designing a download manager using java. Although i am able to download html pages and images as of now, i am facing problems while downloading the video files. Can somebody please guide me as to how to do this.
    Thanks in advance,
    Arun

    All types of data should be downloaded in same way. What is your problem: exception or something else? Post here.

  • Can u please send me a sample code to upload and download a file using java

    Hi,
    Please can u send me a sample code to upload a file and to download the same file from a remote server using a java servlets. The file should be read byte by byte.
    Message was edited by:
    user461713

    Hi, Thank u.
    Sorry, I forgot to attach a code. Here it is.
    Actually i need to upload a file to a remote server and download it from a server to my machine. I'm trying it using servlets and using tomcat5.0 as a servlet container. Here i'm sening a code used to upload a file. Let me know whether it works. Only few lines are here.
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.lang.Object;
    import java.util.*;
    import java.lang.String;
    import com.oreilly.servlet.MultipartRequest;
    public class FileUpload extends HttpServlet{
         public void doPost(HttpServletRequest req, HttpServletResponse res)throws
         ServletException, IOException{
         MultipartRequest multi=new MultipartRequest(req);     
         String file="file1";
         byte[] b=file.getBytes();
         InputStream in=null;
         BufferedInputStream bis=null;
         FileWriter fw=null;
    try{
         in=multi.getInputStream("file1");
    bis=new BufferedInputStream(in);
         File output=new File("/fileuploadtest");
         fw=new FileWriter(output);
              int i;
              i=bis.read();
              while (i != -1) {
    fw.write(i);
    i = bis.read();
         catch(IOException e){
              System.out.println("Exception=" +e);
    finally{
         try{
              if(in!=null)
              in.close();
              if(bis!=null)               
              bis.close();
              if(fw!=null)
              fw.close();
         catch(Exception e){
              System.out.println(e);
    This code is giving error as: cannot resolve symbol: class MultipartRequest
    Why is this happening?
    Pls let me know whether this code works or no and also i have written form.html.
    Can u pls tel me whether there are ways in which i can write a code to upload a file using servlets without using third party packages. Pls help.
    Also how should be the servlet mapping for this code.?
    Regards
    Message was edited by:
    user461713

  • How to Download a file from web server using servlets

    how do we download a file from Java Web Server connecting to oracle database
    it should start as soon a i click a button in my html browser
    please reply as it is needed to complete my project to submited to the collage

    With SQLJ you can do it.
    When you look at:
    http://otn.oracle.com/sample_code/tech/java/sqlj_jdbc/files/basic/basic.htm
    or
    http://otn.oracle.com/sample_code/tech/java/sqlj_jdbc/files/advanced/advanced.htm
    There are samples for reading LONGRAW / BLOB from Database. If you want use it in servlet you have to pass the result to the responce object, set the correct mime-type and set the response.setContentLength( xx). This is for some PlugIns nessessary (pdf).
    regards Dietmar

  • Help with download large file (~50mb) from http protocol

    I'm just using the default HttpURLConnection to download a large file from a server, I can never finish downloading before I get this exception:
    java.net.SocketException: Connection reset
         at java.net.SocketInputStream.read(SocketInputStream.java:168)
         at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
         at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
         at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
         at sun.net.www.MeteredStream.read(MeteredStream.java:116)
         at java.io.FilterInputStream.read(FilterInputStream.java:116)
         at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2446)
         at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2441)
            ...The file is on IIS web server, its a static file, not a server script, web service, or anything special. I usually can download 10-30 mb before this exception occurs. I'm using java 1.6.0_11 on windows xp, anyone have suggestions or experience downloading large files with java?

    Thank you everyone for their suggestions. I tried wget, and it worked fine, but I tried a couple of different clients and they were failing too. I assume wget has resume capabilities, so I debugged the server and found the issue. It was a connection problem on the server end.

  • How to download and upload files in Java?

    Hi, everyone
    How to download and upload files in Java? Do you have some references about this issue or some valuable web link�? Thanks!
    Best Regards,
    Hai.Ren

    This is too vague a question, please be more specific. What protocol would you like to use? HTTP? FTP? Something else?

  • Downloading images and audio file using java

    Dear All
    I have a directory on my webserver which contains images,audio files and many other data files.
    I want to download all the file but the problem is when i download image and save it, it is not viewable. I dont want to use Image class as i may have to downlaod audio files too. Please guis which stream shouldi open to download any kind of content using same code.
    Thanks in advance. And if u have some example please let me know
    Regards
    Jafery

    downloading images and audio file using java -------------------------------
    how to write it back to dataoutputstremI don't understand what you are talking about.
    Server: DataOutputStream -> Client: DataInputStream -- the two is a pair.

  • Java Programm to download some file from a location on internet

    Hi,
    I want to write a java programme which should be capable of download a file(like exe,zip) from the internet. It should also have provision for proxy server and it is going to run behind a firewall.

    Read documentation for URLConnection (and HttpURLConnection) these classes can use proxy (set via system properties as mentioned in documentation), you can obtain InputStream to download remote file.
    Working behind firewall depends on firewall and its configuration.

  • Upload/Download speed of files using Java

    Hey All,
    I have created a signed Java applet which, among various other things, allows uploading and downloading of files between the server and client. Both Upload and Download is handled through HTTP. For Upload I create a multi-part POST request to transfer the data to a script on the server which intercepts it. For download I craft a URL to http://myserver.com/filedirectory/file.extension. From that I form a HttpURLConnection and read from the stream to the file system of the client. This applet is only run on an internal network, which currently has 100mbit connection. However, I am noticing upload/download speeds of less than 1MB/s (I believe 100mbit = 12MB/s approx). I am currently using a buffer size of 8kb.
    Can anyone think of any ways to increase download speed? Would it help to increase the buffer size, knowing we will always be on a closed network? Here Is my upload code, and my download is similar but in the opposite direction.
    int bytesRead = 0;
    byte b[] = new byte[BUFFER_SIZE];
    BufferedInputStream bufin =  new BufferedInputStream(new FileInputStream(f));
    while ((bytesRead = bufin.read(b)) != -1)  {
            * write output
         out.write(b, 0, bytesRead);
         out.flush();
    out.close();
    bufin.close();I have not included the rest of the code which creates the POST request because the upload is otherwise working perfectly despite the speed, and I have confined the bottleneck to this part using debug output.
    Thanks much

    Will removing the flush after every loop somehow decrease accuracy?No.
    Ideally, files should be the same exact size on the server as the client after upload has finished.Deferring the flush() can't change that. It just lets you write in larger chunks, which is always good.
    Which one is the socket receive buffer?The buffer whose size is set by Socket.setReceiveBufferSize().
    Currently the size of BUFFER_SIZE in the example above is set to 8k.That's the application buffer. Good size.

  • Downloading a file from App Server to User's Desktop

    Hi All,
    I know that there are many threads on file upload and download :-)
    I have tried to browse through most of them and could not find my solution.
    The requirement is to place a file in the unix app server directory and allow the user to download it using a link, to the user's desktop. In case you think that this has already been answered in an old thread, kindly give me the pointer. Any sample code for doing this, would be great.
    I know how to upload a file from desktop to table/app server. I know how to download a file from a BLOB column in database.
    Thanks,
    Amit

    You would not be able to use file upload or download beans, as they interact with the database and not the filesystem.
    You would need to write a simple file reader routing in plain java.
    Tapash

  • How to download a file from server machine to client machine using jsp

    Hi,
    In my application, I have an excel file stored on my server machine. How can I download that excel file on to my client machine using jsp. Is there any other way I can open that file from my machine and save it in my machine using jsp/java?
    Its an emergency for me to do this.
    Can anyone provide me the full code to download a file from server machine as I don't have
    time to browse through various sites.
    thanks in advance,
    Tiijnar

    Please post your code using code tags (click on CODE above the text area, when posting)
    response.setContentType("application/octet-stream");Why octet-stream? Set the correct mime-type.
    String disHeader = "Attachment; Filename=\"filename\"";The filename should just be the file's name. Not the complete path to the file! This will tell anyone where the file is located on the server. It's also inconvenient because by default,the browser will suggest it as the name for the download.
    Your way of writing to the output stream is just plain wrong. See this snippet (picked from [http://balusc.blogspot.com/2007/07/fileservlet.html])
            BufferedInputStream input = null;
            BufferedOutputStream output = null;
            try {
                // Open streams.
                input = new BufferedInputStream(new FileInputStream(file), DEFAULT_BUFFER_SIZE);
                output = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE);
                // Write file contents to response.
                byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
                int length;
                while ((length = input.read(buffer)) > 0) {
                    output.write(buffer, 0, length);
                // Finalize task.
                output.flush();
            } finally {
                // Gently close streams.
                close(output);
                close(input);
            }

  • How to download a file from the net and save it into .txt format in a datab

    Can some one show me a tutorial on how to download a file from the net and save it into .txt format in a database?
    Thank you,

    http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html

  • How to create a Web Dynpro Project from Downloaded zip file?

    Hi,
    I have been working in Java Web Dynpro for last 1 month but not able
    to create any Web Dynpro from Downloaded zip file?
    Can anybody tell me how to create a Java Web Dynpro Project from
    Donloaded zip code?
    Regards
    Kaushik Banerjee

    Hi Kaushik,
    You can add the existing zip file into your workspace by the following way -
    First open the NWDS and create a new project by clicking file -> new -> Project -> Simple -> Project
    and then File -> Import -> zipfile and then browse the zip file into the newly created project.
    or else you can also unzip the zip file into a folder and then Use the option of Import an exisitng project into workspace. You can find this in the File-> import -> Existing project into workspace. and then use the Browse option to browse to the existing folder.
    After importing the project you need to rebuild the project
    Regards,
    Raju Bonagiri.

Maybe you are looking for

  • How do you sync iPod Touch music library to iTunes Match for transferring to/using on main computer iTunes?

    Hello, and thank you for any help anyone can offer. I subscribed to iTunes Match to transfer my music that's been stuck on my iPod Touch (iOS 5.1.1) to my new computer. First, some background to explain my problem. On an old laptop, I had 15,000+ son

  • IDES Installation - EHP 7 for SAP ERP 6.0, fails at abap import win 2012 r2 ORA

    Dear gurus: I am having an issue on import abap phase to complete the SAP IDES ERP EHP 7 for ABAP installation.     i am already search on the net, but found nothing about this> my host file on both path: C:\Windows\System32\drivers\etc C:\Windows\Sy

  • Not able to create stdby database through dg.

    Hi, I have tried all options to get the stdby database going through data guard,but at the end i heve come up with nothing.anyways i am able to create stdby database manually.but with data guard.i am using oracle 9.0.1 on win 2000 server and i know t

  • Auto login and report launch for Web Discoverer Plus?

    What url format can I use to auto connect and launch a report in the web version of Discoverer Plus? I've been able to do this fine with Viewer and client/server Plus... Each time I try something it brings me back to the "start_ie.htm"

  • Cant Restore ipod mini

    My Ipod mini has the folder with an exclamation point icon on it and I have tried all the solutions apple provided and none have worked to solve the problem. So I tried to restore my ipod mini and even that didnt work. I switch my ipod mini into disk