¿Cómo puedo usar la biblioteca para descargar un archivo e imprimir los bytes guardados? Intenté usarDescargar archivo usando Java Common Apache?
import static org.apache.commons.io.FileUtils.copyURLToFile;
public static void Download() {
URL dl = null;
File fl = null;
try {
fl = new File(System.getProperty("user.home").replace("\\", "/") + "/Desktop/Screenshots.zip");
dl = new URL("http://ds-forums.com/kyle-tests/uploads/Screenshots.zip");
copyURLToFile(dl, fl);
} catch (Exception e) {
System.out.println(e);
}
}
pero no puedo mostrar los bytes o una barra de progreso. ¿Qué método debo usar?
public class download {
public static void Download() {
URL dl = null;
File fl = null;
String x = null;
try {
fl = new File(System.getProperty("user.home").replace("\\", "/") + "/Desktop/Screenshots.zip");
dl = new URL("http://ds-forums.com/kyle-tests/uploads/Screenshots.zip");
OutputStream os = new FileOutputStream(fl);
InputStream is = dl.openStream();
CountingOutputStream count = new CountingOutputStream(os);
dl.openConnection().getHeaderField("Content-Length");
IOUtils.copy(is, os);//begin transfer
os.close();//close streams
is.close();//^
} catch (Exception e) {
System.out.println(e);
}
}
¿Cómo extendería apache para usar eso? fl = new File (System.getProperty ("user.home"). replace ("\\", "/") + "/Desktop/Screenshots.zip"); dl = new URL ("http://ds-forums.com/kyle-tests/uploads/Screenshots.zip"); OutputStream os = new FileOutputStream (fl); InputStream is = dl.openStream(); CountingOutputStream count = new CountingOutputStream (os); dl.openConnection().getHeaderField ("Content-Length"); IOUtils.copy (is, os); // begin transfer ¿Lo estoy haciendo bien? – Kyle
¿Le importaría agregar el código anterior a su pregunta? Es difícil de leer. Trataré de ayudar. – gigadot
Agregué el código, gracias por ayudarme. – Kyle