Java Downloader.MultiThreading/in part downloading ....Help Needed
hello.
i m making a simple downloader in java.it simply gets URL ,extracts name,makes new file and writes the new dile by downloading it.it works pretty fine.
But i want to increase speed by making it multithreaded,it should download chunks of file concurrently and then join them after finishing job.
Any Help.........
here is code
package dwnlder;
import java.net.*;
import java.io.*;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
class Dwnlder {
public static void main(String[] args) throws Exception
{
System.setProperty("http.proxyHost","192.168.10.50 ");
System.setProperty("http.proxyPort","8080");
URL u=new URL("http://www.rarlab.com/rar/wrar411.exe");
URLConnection uc=u.openConnection();
String path="http://www.rarlab.com/rar/wrar411.exe";
String fName=new File(path).getName();
InputStream ins=u.openStream();
FileOutputStream nf=new FileOutputStream(fName);
System.out.println("Name="+fName);
byte[] b=new byte[1024];
int c=-1;
int i=0;
while((c=ins.read())!=-1)
{
nf.write(c);
System.out.println("Downloading"+i);
i+=1;
}
ins.close();
nf.close();
System.out.println("Done");
}
}
Waiting for ur reply.........
Re: Java Downloader.MultiThreading/in part downloading ....Help Needed
Quote:
it should download chunks of file concurrently
Does the server support sending selected sections/chunks of a file?
Re: Java Downloader.MultiThreading/in part downloading ....Help Needed
I dont have idea about this,,please explain
Re: Java Downloader.MultiThreading/in part downloading ....Help Needed
If the server is not setup such that it can send different chunks of a file to different requests then this will not work.
That's what Norm is saying.
A standard HTTP link like above does not do that.
It takes a single requests and returns the whole thing to that request.