- Obtenga la longitud del contenido del archivo para descargar.
- Dividir según un criterio (tamaño, velocidad, & hellip;).
- ejecutar múltiples hilos para descargar el archivo a partir de las diferentes posiciones,
y guardarlas en archivos diferentes: myfile.part1
, myfile.part2
, y hellip;
- Una vez descargado, una las partes en un solo archivo.
He probado el siguiente código para obtener la longitud del contenido:
public Downloader(String path) throws IOException {
int len = 0;
URL url = new URL(path);
URLConnection connectUrl = url.openConnection();
System.out.println(len = connectUrl.getContentLength());
System.out.println(connectUrl.getContentType());
InputStream input = connectUrl.getInputStream();
int i = len;
int c = 0;
System.out.println("=== Content ===");
while (((c = input.read()) != -1) && (--i > 0)) {
System.out.print((char) c);
}
input.close();
}
Aquí hay un código de ejemplo para unirse a los archivos:
public void join(String FilePath) {
long leninfile=0, leng=0;
int count=1, data=0;
try {
File filename = new File(FilePath);
RandomAccessFile outfile = new RandomAccessFile(filename,"rw");
while(true) {
filename = new File(FilePath + count + ".sp");
if (filename.exists()) {
RandomAccessFile infile = new RandomAccessFile(filename,"r");
data=infile.read();
while(data != -1) {
outfile.write(data);
data=infile.read();
}
leng++;
infile.close();
count++;
} else break;
}
outfile.close();
} catch(Exception e) {
e.printStackTrace();
}
}
Su pregunta no es muy clara o específica. ¿Podría posiblemente aclarar? Gracias –
@ all: ** ¡Las preguntas también necesitan votos! ** –