Download a file using a url

Hi all,
is there a class that allows to download a file giving an url as parameter?
Thanks a lot, it will make me win a bet I made with a .net supporter.
Marco

No there is no class, but you can write the stuff yourself
URL downloadURL = new URL("http://www.download.xxx/index.html");
FileWriter local = new FileWriter("C:\index.html");
InputStream internet = downloadURL.openStream();
byte[] buffer = new byte[1000];
int bytesRead;
while (true) {
    bytesRead = internet.read(buffer);
    if (bytesRead == -1) break;
    local.write(buffer, 0, bytesRead);
}The code reads the file from "http://www.download.xxx/index.html" and writes it to "C:\index.html".

Similar Messages

  • How to download video files using http urls through OSB

    Hi all,
    I am working on a requirement where I need to download the video using http url of that video through OSB. Is it possible to convert the video files hosted in a server into base64 code using OSB ? Kindly help me on this.
    Thanks
    Edited by: 887737 on Jul 25, 2012 3:26 AM

    Hi,
    I believe you can get the video file using file transport and then convert it into base64 using a java call out...
    This may help...
    https://blogs.oracle.com/ateamsoab2b/entry/an_example_of_how_to
    Cheers,
    Vlad

  • I can not download any files using Safari ? when I choose to download application file the URL include the file name and stop responding. Any help??

    I can not download any files using Safari ? when I choose to download application file the URL include the file name and stop responding. Any help??

    Please read this whole message before doing anything.
    This procedure is a test, not a solution. Don’t be disappointed when you find that nothing has changed after you complete it.
    Step 1
    The purpose of this step is to determine whether the problem is localized to your user account.
    Enable guest logins* and log in as Guest. For instructions, launch the System Preferences application, select Help from the menu bar, and enter “Set up a guest account” (without the quotes) in the search box.
    While logged in as Guest, you won’t have access to any of your personal files or settings. Applications will behave as if you were running them for the first time. Don’t be alarmed by this; it’s normal. If you need any passwords or other personal data in order to complete the test, memorize, print, or write them down before you begin.
    Test while logged in as Guest. Same problem(s)?
    After testing, log out of the guest account and, in your own account, disable it if you wish. Any files you created in the guest account will be deleted automatically when you log out of it.
    *Note: If you’ve activated “Find My Mac” or FileVault in Mac OS X 10.7 or later, then you can’t enable the Guest account. The Guest login created by “Find My Mac” is not the same. Create a new account in which to test, and delete it, including its home folder, after testing.
    Step 2
    The purpose of this step is to determine whether the problem is caused by third-party system modifications that load automatically at startup or login.
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards. Boot in safe mode* and log in to the account with the problem. The instructions provided by Apple are as follows:
    Be sure your Mac is shut down.
    Press the power button.
    Immediately after you hear the startup tone, hold the Shift key. The Shift key should be held as soon as possible after the startup tone, but not before the tone.
    Release the Shift key when you see the gray Apple icon and the progress indicator (looks like a spinning gear).
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including wireless networking on certain Macs.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    *Note: If FileVault is enabled under Mac OS X 10.7 or later, you can’t boot in safe mode.
    Test while in safe mode. Same problem(s)?
    After testing, reboot as usual (i.e., not in safe mode) and verify that you still have the problem. Post the results of steps 1 and 2.

  • Can any one help me to download a file using struts2

    can any send me a sample program to download a file using struts2
    regards
    saradhi

    i cannot find it in google please help me by sending a link or a code
    thanking u
    regards saradhi
    while i am executing this code i am getting error
    javax.servlet.ServletException: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
         org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
         org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
    root cause
    java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
         org.apache.struts2.dispatcher.StreamResult.doExecute(StreamResult.java:189)
         org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:178)
         com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:348)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
         com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
         com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
         org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
         com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:167)
         com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:121)
         com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
         com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
         com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
         com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
         org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
         org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)
         org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17
    and my code is as follows
    download action.java
    package com.mss.mirage;
    import java.io.InputStream;
    import org.apache.struts2.ServletActionContext;
    import com.opensymphony.xwork2.ActionInvocation;
    import com.opensymphony.xwork2.Action;
    * Demonstrates file resource download.
    * Set filePath to the local file resource to download,
    * relative to the application root ("/images/struts.gif").
    public class FileDownloadAction implements Action {
    private String inputPath;
    private String contentType;
    private String inputName;
    private String contentDisposition;
    private String fileId;
    private int bufferSize;
    public void setInputPath(String value) {
    inputPath = value;
    public InputStream getInputStream() throws Exception {
    return ServletActionContext.getServletContext().getResourceAsStream(getInputPath());
    public String execute() throws Exception {
    return SUCCESS;
    public String getInputPath() {
    return inputPath;
    public String getContentType() {
    return contentType;
    public void setContentType(String contentType) {
    this.contentType = contentType;
    public String getInputName() {
    return inputName;
    public void setInputName(String inputName) {
    this.inputName = inputName;
    public String getContentDisposition() {
    return contentDisposition;
    public void setContentDisposition(String contentDisposition) {
    this.contentDisposition = contentDisposition;
    public String getFileId() {
    return fileId;
    public void setFileId(String fileId) {
    this.fileId = fileId;
    public int getBufferSize() {
    return bufferSize;
    public void setBufferSize(int bufferSize) {
    this.bufferSize = bufferSize;
    download.jsp
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <html>
    <head>
    <title>Showcase - Fileupload</title>
    </head>
    <body>
    <h1>File Download Example</h1>
    <ul>
    <li>
    <s:url id="url" action="download2"/><s:a href="%{url}">Download ZIP file.</s:a>
    The browser should prompt for a location to save the ZIP file.
    </li>
    </ul>
    </body>
    </html>
    struts.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
    <package name="download" extends="struts-default" namespace="/download">
    <default-action-ref name="download"/>
    <action name="download2" class="com.mss.mirage.FileDownloadAction">
    <param name="inputPath">"c:\images\struts.zip"</param>
    <result name="success" type="stream">
    <param name="contentType">application/zip</param>
    <param name="inputName">inputStream</param>
    <param name="contentDisposition">filename="c:\images\struts.zip"</param>
    <param name="bufferSize">4096</param>
    </result>
    </action>
    </package>
    </struts>

  • How to download a file using servlet

    I have a problem about downloading a file using a servlet.
    Anybody can help me?
    Thanks

    I am assuming that you want to write a servlet that, when invoked by a user (for instance, through a URL link), will download a file using the "save as" dialog (on Windows, for example) in the user's browser.
    In such a case, all you need to do is get the OutputStream from the response object, set the proper MIME type header, and write the file. Here is an (untested, not even compiled) skeleton.
    public class MyServlet extends HttpServlet {
    protected void doGet (HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
    ServletOutputStream out = resp.getOutputStream ();
    resp.setContentType ("application/x-foobar");
    while (/* whatever */) {
    In this loop, you generate your "file's" data.
    You can compute it on the fly, pull it from a database,
    read it from a "real" file, or any other means you can dream up.
    The sample line below just writes some of the data (for example,
    a byte array) to the user's browser via the output stream out.
    out.write (data);
    out.flush ();
    Go to http://java.sun.com/j2ee/sdk_1.3/techdocs/api/index.html
    for the JavaDoc on the classes used.
    Cheers!
    Jerry Oberle

  • How to get Header in Downloaded .xls file using  GUI_Download function

    How to get Header in Downloaded .xls file using  GUI_Download function ???
    How to use the the Header parameter available in GUI_Download function .

    HI,
    see this sample code..
    data : Begin of t_header occurs 0,
           name(30) type c,
           end of t_header.
    data : Begin of itab occurs 0,
           fld1 type char10,
           fld2 type char10,
           fld3 type char10,
           end   of itab.
    DATA: v_pass_path TYPE string.
    append itab.
    itab-fld1 = 'Hi'.
    itab-fld2 = 'hello'.
    itab-fld3 = 'welcome'.
    append itab.
    append itab.
    append itab.
    append itab.
    append itab.
    t_header-name = 'Field1'.
    append t_header.
    t_header-name = 'Field2'.
    append t_header.
    t_header-name = 'Field3'.
    append t_header.
      CALL FUNCTION 'GUI_FILE_SAVE_DIALOG'
        EXPORTING
          default_extension     = 'XLS'
        IMPORTING
          fullpath              = v_pass_path.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename                        = v_pass_path
          filetype                        = 'DBF'
        TABLES
          data_tab                        = itab
          FIELDNAMES                      = t_header
    Cheers,
    jose.

  • How do I download PDF files using Safari.  All I get is a black screen.

    How do I download PDF files using Safari.  All I get is a black screen.

    Back up all data.
    Quit Safari. In the Finder, select Go ▹ Go to Folder... from the menu bar, or press the key combination shift-command-G. Copy the line of text below into the box that opens, and press return:
    /Library/Internet Plug-ins
    From the folder that opens, remove any items that have the letters “PDF” in the name. You may be prompted for your login password. Then launch Safari and test.
    If you still have the issue, repeat with this line:
    ~/Library/Internet Plug-ins
    If you don’t like the results of this procedure, restore the items from the backup you made before you started. Relaunch Safari again.

  • To download a file using Ftp.

    I am making a web application using struts framework . now on one jsp page i'll have to give the list of files on the ftp server and link to download those files using ftp from the ftp server.
    I have made functions using jakarta commons.net library by which i m able to show the list of files on jsp page but i m not able to give download link bcos using the function the file is downloaded on the server on which my application is running . and not from which i am accessing through the browser.........
    If any one have any idea pls let me know...........?
    Regards,
    Neeraj.

    If it's anonymouse FTP to download from the server, just make the page have a link to the FTP site..
    some file

  • Download a file using GetRight

    How is it possibe to download a file using a downloader like getright? I am trying to get
    oracle-xe-universal_10.2.0.1-1.0_i386.deb
    but if I transfer it to Getright it fails to login, although I ve done it using the browser.

    Well, normally it does. It's only at oracle.com that it doesn't work, and I wonder why. I tried putting directly the uid and the passwd but it didn't work either.

  • Download a file using servlet

    Hi,
    i need to download a file using servlet (jsp frontend) and if the download is successful, then a success message shud be displayed on the jsp.
    i have tried it using MultipartResonse object and have been able to download the file. The problem is displaying the message on a jsp after download. After download if i use RequestDispatcher object to forward control to another jsp, it doesnt happen.
    Can anyone help me with this?

    Hi,
    You can check :-
    http://www.servletsuite.com/servlets/download.htm
    Best of luck.
    R S

  • Two different methods for downloading a file using URL...

    I was just wondering if someone could shed some light on whether I should be downloading files using java.net.URL or java.net.URLConnection
    Here are two ways that I have found to work (and yes I realize that one is outputting to a stream and the other is getting put into a StringBuffer):
          InputStream in = url.openStream();
          byte[] b = new byte[buffSize];
          fileOutStream = new FileOutputStream(fileToBeCreated);
          while ((bytesRead = in.read(b)) != -1){
            totalFileSize+=bytesRead;
            fileOutStream.write(b, 0, bytesRead);
          }and
          URLConnection _con = url.openConnection();
          in = new BufferedReader(new InputStreamReader(_con.getInputStream()));
          String inputLine;
          while ((inputLine = in.readLine()) != null){
              webPageStringBuff.append(inputLine+"\r\n");
          }In both of the above cases url is just a URL object that has already been instantiated with a valid URL.
    So, just to re-iterate, I realize that the output portion of this code is doing something different (i.e. writing to a stream as opposed to appending to a StringBuffer) but I would like to know whether there is any reason to choose using the URLConnection to get the stream as opposed to using the URL to get the stream.
    Thanks,
    Tim

    hi,
    try out the following code
    // Program: copyURL.java
    // Author: Anil Hemrajani ([email protected])
    // Purpose: Utility for copying files from the Internet to local disk
    // Example: 1. java copyURL http://www.patriot.net/users/anil/resume/resume.gif
    // 2. java copyURL http://www.ibm.com/index.html abcd.html
    import java.net.*;
    import java.io.*;
    import java.util.Date;
    import java.util.StringTokenizer;
    class copyURL
    public static void main(String args[])
    if (args.length < 1)
    System.err.println
    ("usage: java copyURL URL [LocalFile]");
    System.exit(1);
    try
    URL url = new URL(args[0]);
    System.out.println("Opening connection to " + args[0] + "...");
    URLConnection urlC = url.openConnection();
    // Copy resource to local file, use remote file
    // if no local file name specified
    InputStream is = url.openStream();
    // Print info about resource
    System.out.print("Copying resource (type: " +
    urlC.getContentType());
    Date date=new Date(urlC.getLastModified());
    System.out.println(", modified on: " +
    date.toLocaleString() + ")...");
    System.out.flush();
    FileOutputStream fos=null;
    if (args.length < 2)
    String localFile=null;
    // Get only file name
    StringTokenizer st=new StringTokenizer(url.getFile(), "/");
    while (st.hasMoreTokens())
    localFile=st.nextToken();
    fos = new FileOutputStream(localFile);
    else
    fos = new FileOutputStream(args[1]);
    int oneChar, count=0;
    while ((oneChar=is.read()) != -1)
    fos.write(oneChar);
    count++;
    is.close();
    fos.close();
    System.out.println(count + " byte(s) copied");
    catch (MalformedURLException e)
    { System.err.println(e.toString()); }
    catch (IOException e)
    { System.err.println(e.toString()); }
    ok

  • Buffered Downloading of a File using a URL

    Hi All,
    I have been trying to download a file (online - using URL) using the Data Socket Read. But on downloading the file (Minimum Size: 250 MB) the labview memory gets built up i.e I will have to wait till all the packets pertaining to that file are received by the client. I tried using buffered read in Data Socket Open, so that i would to able to obtain instantaneous packets received. But still the memory builds up during the download process. Can anyone please suggest me a solution so that i would be able to obtain the packets as and when they are received by the client instead of waiting for the entire file to be received by the client ?
    The data downloaded will be in unformatted text and i have attached the VI for reference. Thanks in advance.
    Regards,
    S.P.Prasaanth

    If you are keeping the file in memory as you are downloading it then it will of course use lots of memory (essentially an array of bytes). I think the key thing here is to periodically flush the chunks data received to disk.
    I don't know if this is possible using the DataSocket functions (it maybe buffers the network data, not the file part?) but it should be possible using the raw TCP/IP functions or perhaps even a .NET library (HttpWebRequest?).
    Edit: On looking at your VI, I can't see any obvious cause for the whole file to be in memory unless it's something relating to how DataSockets are implemented internally. In which case - my point still stands that you could try the .NET library or doing the http by raw TCP/IP.

  • Problem downloading rar file using HttpURLConnection

    I'm trying to read a rar(archiving) file from the Internet using a HttpUrlConnection.
    The program seems to work fine - however the download is not the same size as the file if downloaded through a browser.
    The archive is 52,332kb when downloaded through a browser
    and 4kb smaller when I try to download it.
    When I try to extract the downloaded file (with winRAR) the header is corrupt and there is an unexpected end of archive.
    Here is the pertinent code.
    try
                // configure and open connection
                HttpURLConnection conn = (HttpURLConnection)   currURL.openConnection(); // currURL is a URL object
                conn.setRequestProperty("Connection", "Keep-Alive");
                conn.setRequestProperty("Accept-Encoding", "gzip,deflate" );
                conn.setRequestProperty("Content-type", "application/x-rar-compressed" );
                conn.setRequestProperty("Cookie", cookie);   
                conn.connect();
                // get an input stream from the HttpURLConnection object    
                InputStreamReader isr = new InputStreamReader( conn.getInputStream() );
                BufferedReader in = new BufferedReader( isr );
                /* the string file_name has been parsed from the url
                 * and is in the format file_name.rar */
                File dest = new File("C:\\my_folder\\"+file_name);
                // open output stream
                OutputStream os = new FileOutputStream( dest );
                OutputStream buffer = new BufferedOutputStream( os );
                int data;
                while ( (data = in.read() ) != -1 )
                   buffer.write(data);
                // close streams
                in.close();
                os.close();
    catch( IOException iox)
         iox.printStackTrace();
    }Thanks in advance.

    Thanks ejp. I closed 'buffer' instead - that fixes the size problem.
    The archive is now exactly the same size as it should be - but the header information is still corrupt.
    When I compared the files using a binary comparison program it
    said that the files although the same size were different by approx. 6.7mb out of 53.5mb.
    I'm perplexed as to what this difference could stem from; is it the encoding, the charset, something similar?
    The underlying file I'm trying to download is an avi if that makes any difference.

  • Download a file using http proxy - java

    Hi,
    I'm trying to download a pic using http proxy.
    Means - I have the url to the pic, I want to get it by my proxy
    Can anyone help me with that? any link, example etc...?
    Thanks

    This works:String server="hostname";
    String user="user ID";
    String passwd="password";
    try {
         sun.net.ftp.FtpClient client = new sun.net.ftp.FtpClient();
         client.openServer(server);
         client.login(user, passwd);
         client.cd("..");
         sun.net.TelnetInputStream in = client.get("File to be downloaded");
         BufferedReader br = new BufferedReader(new InputStreamReader(in));
         String s;
         while((s=br.readLine()) != null) {
              System.out.println(s);
         in.close();
             br.close();
    catch (IOException ioe) {
         ioe.printStackTrace();
    }Mark

  • Help downloading a file using HttpsURLConnection

    Hi All,
    I am trying to connect to a page that is actually a cgi page and download a file from there using the httpsURLConnection.
    When I run the URL from the browser, I get an authentication challenge...I authenticate, then I get the Download file box where I can download the file.
    When I run my code to connect to the URL using the httpsURLConnection, I'm able to authenticate using post then what comes back is the html for the front page. (like an index page or something).
    Is this even possible? Any help would be greatly appreciated.
    Here's some of the code...
    URL url = new URL ("https://.... /file.cgi?.....");
    HttpsURLConnection c = null;
    c = (HttpsURLConnection)url.openConnection();
    c.setRequestMethod("POST");
    c.setRequestProperty("Authorization", "Basic " + BasicAuth.encode(user, password));
    c.setRequestProperty("User-Agent", "Mozilla/4.0(compatible)");
    c.setRequestProperty("Content-Disposition", "attachment;filename=\"events.csv\"");
    c.setRequestProperty("Content-Type", "application/x-csv");
    c.setRequestProperty( "Accept", "application/x-csv");
    c.connect();
    //System.out.println(c.getContentEncoding());
    System.out.println("Response code: " +c.getResponseCode());
    InputStream in = c.getInputStream();
    StringBuffer b = new StringBuffer();
    BufferedReader r = new BufferedReader(new InputStreamReader(in));
    String line;
    while ((line = r.readLine()) != null)
    b.append(line);
    String s = b.toString();
    System.out.println(s);

    I just noticed that the page it brings back is exactly the page that I get in the browser when I do not type the attributes after the https://---.cgi?.
    For example the url is ....cgi?subcmd=Download
    So, is there some place I can set these attributes within the java code that isn't in the url field?

Maybe you are looking for

  • Can't start iPod in Manual Mode

    I can't seem to start an 30GB iPod in Manual Mode, even while pressing the command and option keys while starting up. Any ideas on how to force it into Manual Mode?

  • To know the name of the job

    Hi all,    Could u say me how to get the name of the job that is being used in the program if if the name of the report is known?

  • Swapping Powerbook Displays

    Hi all, my Powerbook 1.5 Ghz computer's logic board died, so I got a new Powerbook (1.67 Ghz). However the new Powerbook's display isn't in as good of a shape as my old one - there are a couple slightly noticeable darkish "spots" on it. Now, I'm thin

  • Security constaint in Oracle 10.1.2 - Web.xml

    hi, I can access my URL in both http and https . 1) http://myURL.com 2) https://myURL.com:4444 But I want this logic to be contained in Web.xml where in only for some resource , I need to use https. I put the following in Web.xml ...But it is not wor

  • Steps to follow while creating new report...

    HI friends, Can any one please help me with the things to keep in mind and the process to follow while going for creating new reports in BI 7.0. We are about to create some new reports ., also the things to keep in mind while getting the requirement