Aquí va el code para descargar por http con la librería httpclient de apache [Enlace externo eliminado para invitados] (+httpcorey +commonlogins)

Código: Seleccionar todo

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.File;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

    DefaultHttpClient httpclient = new DefaultHttpClient();
    
    public File data;
	public static void main(String[] args) throws IOException, Exception {

   getMetodo("AQUÍ LA URL") }
    protected void getMetodo(String url) throws IOException {//,       AQUI INICIA

        HttpGet httpget = new HttpGet(url);
  

        httpget.setHeader("Cookie", null);
        httpget.setHeader("User-Agent","Descargador 0.1 ");
 
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();


        int content;
        data =new File("temp.archiv");
        byte [] ibuffer = new byte[65536];
        InputStream is = entity.getContent();

        FileOutputStream fos = new FileOutputStream(data);
        int inByte;
        int inBytes = 0;
        while((inByte = is.read()) != -1){ fos.write(inByte) ;}

        fos.close();
        is.close();

    }
El buffer es un poco exagerado pero me mola ponerlo de esa envergadura xD
RapidShare.de will permanently shut down the servers on 1. March 2010! nein ..
PD:Policia española psicópata
∩____∩
| (• ◡•)|
Responder

Volver a “Fuentes”