Results 1 to 4 of 4
  1. #1
    falcommoney is offline Member
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

    Default Help needed with downloader in java

    Hello,

    I am working on a downloader in java.
    I want it to download a file, and execute it.

    This is my code, but I cant get it to work. It does download and save the file, but it doesnt execute it. Can somebody help me?

    This is my code:
    Java Code:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.awt.*;
    
    public class SampleFile
    {
    public static void main(String args[]) throws IOException
    {
    
    java.io.BufferedInputStream in = new java.io.BufferedInputStream(new
    
    java.net.URL("link to file").openStream());
    java.io.FileOutputStream fos = new java.io.FileOutputStream("filename");
    java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
    byte data[] = new byte[1024];
    while(in.read(data,0,1024)>=0)
    {
    bout.write(data);
    }
    
    //FILE OPENING!
    File f = new File("filename");
    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    DataInputStream dis = new DataInputStream(bis);
    bout.close();
    in.close();
    }
    
    
    }
    I would also like to choose the path of where to save the downloaded file.

    Is this possible?

    Thanks in advance!

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    12

    Default

    are you trying to open the file or execute it??
    to execute use exec in the Runtime class.
    Runtime (Java 2 Platform SE v1.4.2)

    and yes you can set the path too.
    Java Code:
    File f = new File("c:\\filename");
    or (better)
    File f = new File("c:"+File.separator+"filename");
    or even
    File f = new File("path","filename");
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    falcommoney is offline Member
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

    Default

    What is ther difference between opening and executing?

    Thanks!

  4. #4
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    12

    Default

    when you are running excel, that's executing.
    when you are opening an excel file, that's opening.

    err... you'll get use to the terms eventually.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

Similar Threads

  1. Replies: 8
    Last Post: 02-09-2009, 12:58 AM
  2. Java experts needed- 30 minute online Java projects
    By michelle in forum Jobs Offered
    Replies: 0
    Last Post: 03-06-2008, 12:47 AM
  3. Creating a Downloader using JAVA
    By shinojkk in forum New To Java
    Replies: 0
    Last Post: 01-08-2008, 06:08 PM
  4. Torrent Episode Downloader 0.90
    By levent in forum Java Software
    Replies: 0
    Last Post: 08-02-2007, 06:56 PM
  5. Torrent Episode Downloader 0.80
    By levent in forum Java Software
    Replies: 0
    Last Post: 06-01-2007, 07:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •