Here is my code
The file is not getting downloaded properly some parts left at the end what should i do?
Code:
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;
import java.net.URL;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.net.URLConnection;
/**
*
* @author Admin
*/
public class SWfDowloader {
public static void main(String a[]) throws Exception{
String swf_path = "http://www.prototypejs.org/assets/2008/1/25/prototype-1.6.0.2.js";
URL swf_url = new URL(swf_path);
byte address[] = {(byte)144,(byte)16,(byte)192,(byte)245};
SocketAddress socket_address = new InetSocketAddress(InetAddress.getByAddress(address),8080);
Proxy proxy = new Proxy(Proxy.Type.HTTP,socket_address);
URLConnection url_conn = swf_url.openConnection(proxy);
url_conn.connect();
BufferedInputStream swf_in_stream = new BufferedInputStream(url_conn.getInputStream());
FileOutputStream swf_file = new FileOutputStream("d:/test.js");
BufferedOutputStream swf_out_stream = new BufferedOutputStream(swf_file);
byte bytes[] = new byte[512];
int read_bytes = 0;
while((read_bytes=swf_in_stream.read(bytes))!=-1){
System.out.println(read_bytes);
swf_out_stream.write(bytes, 0,read_bytes);
}
swf_in_stream.close();
swf_file.close();
swf_out_stream.close();
}
}
Comment