Copy files from Webserver

View: New views
1 Messages — Rating Filter:   Alert me  

Copy files from Webserver

by sandeep_khurana :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I want to copy a file kept on a webserver. i tried copying it through URLConnection but the speed at which the gets copied is very slow (atleast 10 times slow) than what I get from copying it through a Browser (IE or Firefox).

the code is:
url = new URL(url); urlConn = url.openConnection();  
in = new BufferedInputStream(urlConn.getInputStream());
fos = new FileOutputStream(new File(localFile));
  byte[] readBytes = new byte[BUFFER_SIZE];
  int iCurrentBytes; while (true) {
iCurrentBytes = in.read(readBytes, 0, BUFFER_SIZE);  
if (iCurrentBytes < 0)color="navy">{
break;
}
fos.write(readBytes, 0, iCurrentBytes);
}
fos.flush();


BufferSize is 8K. it takes around 38 sec. for 75 MB of file over a webserver hosted on my PC. the same takes 5 sec. hardly if i download the same from IE or firefox.

I have tried the following combinations while getting the metrics:
1. downloading the file first from IE then from the java code.
2. downloading another 75 MB file first from java code and then from IE
in both the cases the browser took 8-10 times less time. I did this because I thought it was a caching issue but no help.

Is there something that I am missing.