同時下載多個文件
view plaincopy to clipboardprint?
package com
public class Files {
/***
* 獲取應用程序的根目錄
* @return 應用程序根目錄
*/
public static String getSysPath(){
return System
}
}
package com
public class Files {
/***
* 獲取應用程序的根目錄
* @return 應用程序根目錄
*/
public static String getSysPath(){
return System
}
}view plaincopy to clipboardprint?
view plaincopy to clipboardprint?
<PRE class=csharp name=
import java
import java
import java
import java
import
import
import re
public class WebSpider implements Runnable{
private Http http = new Http();
private String webAddress =
private String destFile =
public void setWebAddress(String webAddress){
this
}
public void setDestFile (String destFile){
this
}
public boolean download() throws IOException
HttpURLConnection httpConn = null;
try {
URL url = new URL(webAddress);
httpConn = (HttpURLConnection) url
(
(
InputStream in = ();
String fileType = http
System
FileOutputStream out = new FileOutputStream(new File(destFile + fileType));
int chByte = in
while (chByte !=
out
//System
chByte = in
}
} catch (Exception ex) {
System
} finally {
();
}
return true;
}
public void run() {
try {
//System
download();
} catch (IOException e) {
e
} catch (InterruptedException e) {
e
}
}
}
</PRE>
view plaincopy to clipboardprint?package re
import java
import java
import java
import java
import
import
import re
public class WebSpider implements Runnable{
private Http http = new Http();
private String webAddress =
private String destFile =
public void setWebAddress(String webAddress){
this
}
public void setDestFile (String destFile){
this
}
public boolean download() throws IOException
HttpURLConnection httpConn = null;
try {
URL url = new URL(webAddress);
httpConn = (HttpURLConnection) url
(
(
InputStream in = ();
String fileType = http
System
FileOutputStream out = new FileOutputStream(new File(destFile + fileType));
int chByte = in
while (chByte !=
out
//System
chByte = in
}
} catch (Exception ex) {
System
} finally {
();
}
return true;
}
public void run() {
try {
//System
download();
} catch (IOException e) {
e
} catch (InterruptedException e) {
e
}
}
}
view plaincopy to clipboardprint?
<PRE class=csharp name=
import java
import com
public class Crawl {
/**
* @param args
* @throws IOException
* @throws InterruptedException
*/
public static void main(String[] args) throws IOException
long begin = System
WebSpider spider
WebSpider spider
spider
spider
spider
spider
Thread t
Thread t
t
t
t
t
System
System
}
}</PRE>
<PRE class=csharp name=
<PRE class=csharp name=
<PRE class=csharp name=
From:http://tw.wingwit.com/Article/program/Java/gj/201311/27577.html