J2ee实现批量下载 给位大虾,今天想做一个批量下载,希望大家能给我点指引,我想实现的功能就是每个链接前面有一个复选框,下面有一个下载选中项,我希望单击就能下载选中的那些链接,大家都来指教一下该怎么做! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 文件的传输都是用的流,你可以用一个流传输多个文件,一次一个文件,传完一个flash下 import java.io.BufferedReader;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;import java.util.regex.Matcher;import java.util.regex.Pattern;public class Test { public static void main (String[] args) { System.out.println(area("http://ipwhois.cnnic.net.cn/ipwhoisresult.php?query_option=ipv4&txtquery=123.123.123.123")); } public static String area(String urlAddress){ try { URL url= new URL(urlAddress); HttpURLConnection h=(HttpURLConnection)url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(h.getInputStream())); StringBuilder sb = new StringBuilder(); String s; while((s = in.readLine()) != null){ sb.append(s); } s = sb.toString(); return mat(s, "网络名.*?>\\s+(.*?)<"); } catch (Exception e) { e.printStackTrace(); } return "未找到相应匹配"; } public static String mat(String source, String regex){ Pattern p = Pattern.compile(regex); Matcher matcher = p.matcher(source); while(matcher.find()){ return matcher.group(1); } return " "; }}getInputStream()就是文件流,保存到本地,等批量下载后用zip打包 import org.apache.tools.zip.ZipEntry;import org.apache.tools.zip.ZipFile;import org.apache.tools.zip.ZipOutputStream; public static File zipFile(String zipName, File[] files) { File file = new File(zipName); try { ZipOutputStream out = new ZipOutputStream(file); for(int i = 0; i < files.length; i++) { if(files[i] == null) { continue; } FileInputStream in = new FileInputStream(files[i]); ZipEntry entry = new ZipEntry(files[i].getName()); out.putNextEntry(entry); int len = 0; byte[] bytes = new byte[256]; while((len = in.read(bytes, 0, bytes.length)) != -1) { out.write(bytes, 0, len); } out.closeEntry(); in.close(); } out.flush(); out.close(); } catch(Exception e) { e.printStackTrace(); } return file; } session和cookie的问题所在? 一个很简单的问题 hibernate框架居然能访问对象的私有属性,它是怎么做到的?? 请问有什么开源制表工具! JSP求助 初学者请教各位前辈,如何配置j2ee的开发环境? tomcat问题 高手请进,求教一关于jnlp的socket编程问题 请问一个sql server数据源配置问题 javamail的程序,用单位的邮箱测试收邮件时挺好,用sina等公共邮箱就乱码 URL编码是干吗的?什么时候用呢? java有关
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class Test {
public static void main (String[] args) {
System.out.println(area("http://ipwhois.cnnic.net.cn/ipwhoisresult.php?query_option=ipv4&txtquery=123.123.123.123"));
}
public static String area(String urlAddress){
try {
URL url= new URL(urlAddress);
HttpURLConnection h=(HttpURLConnection)url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(h.getInputStream()));
StringBuilder sb = new StringBuilder();
String s;
while((s = in.readLine()) != null){
sb.append(s);
}
s = sb.toString();
return mat(s, "网络名.*?>\\s+(.*?)<");
} catch (Exception e) {
e.printStackTrace();
}
return "未找到相应匹配";
}
public static String mat(String source, String regex){
Pattern p = Pattern.compile(regex);
Matcher matcher = p.matcher(source);
while(matcher.find()){
return matcher.group(1);
}
return " ";
}
}getInputStream()就是文件流,保存到本地,等批量下载后用zip打包
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;
import org.apache.tools.zip.ZipOutputStream; public static File zipFile(String zipName, File[] files) {
File file = new File(zipName); try {
ZipOutputStream out = new ZipOutputStream(file); for(int i = 0; i < files.length; i++) {
if(files[i] == null) {
continue;
} FileInputStream in = new FileInputStream(files[i]);
ZipEntry entry = new ZipEntry(files[i].getName());
out.putNextEntry(entry);
int len = 0;
byte[] bytes = new byte[256]; while((len = in.read(bytes, 0, bytes.length)) != -1) {
out.write(bytes, 0, len);
} out.closeEntry();
in.close();
} out.flush();
out.close();
}
catch(Exception e) {
e.printStackTrace();
} return file;
}