Using this code I can download all files in a zip file:
package zip;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipOutputStream;
public class Zip extends java.lang.Object
{
public String filePath;
private FileOutputStream fileOutputStream;
private byte[] bytes;
public Zip(String filePath) throws FileNotFoundException
{
this.filePath = filePath;
this.fileOutputStream = new FileOutputStream(filePath);
}
public void zip() throws IOException
{
bytes = new byte[(int) this.fileOutputStream.size()];
this.fileOutputStream.write(bytes);
this.fileOutputStream.close();
}
}
And then I try to use the code to download all the songs from Melanie Fiona's official music-sharing site.
try {
FileOutputStream fileOutputStream = new FileOutputStream("C:/Users/us/Desktop/test.zip");
Zip z = new Zip("");
int len;
byte[] buffer = new byte[1024];
while ((len = fileInputStream.read(buffer))!= -1) {
z.zip();
fileOutputStream.write(buffer, 0, len);
}
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
The code works well when I'm not using a website to download the files, but it takes much ac619d1d87
Related links:
Comments