代码拉取完成,页面将自动刷新
package cc.openhome;
import java.net.URL;
import java.util.concurrent.*;
import java.io.*;
public class Pages {
private URL[] urls;
private String[] fileNames;
private Executor executor;
public Pages(URL[] urls, String[] fileNames, Executor executor) {
this.urls = urls;
this.fileNames = fileNames;
this.executor = executor;
}
public void download() {
for (int i = 0; i < urls.length; i++) {
URL url = urls[i];
String fileName = fileNames[i];
executor.execute(() -> {
try {
dump(url.openStream(), new FileOutputStream(fileName));
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});
}
}
private void dump(InputStream src, OutputStream dest) throws IOException {
try (InputStream input = src; OutputStream output = dest) {
byte[] data = new byte[1024];
int length;
while ((length = input.read(data)) != -1) {
output.write(data, 0, length);
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。