展开全部
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
public class URLConnectionDemo {
public static void main(String[] args) throws Exception{
URLConnection uc = url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String str= null;
String xz = "";
while((str=br.readLine())!=null){
if(str.indexOf(".swf")!=-1){
try{
xz = str.substring(str.lastIndexOf("http"),str.indexOf(".swf") + 4);
}catch(Exception e){
}
}
}
System.out.println("下载32313133353236313431303231363533e78988e69d8331333337616539地址为:" + xz);
getDondow(xz,"F:\\xx.swf");
}
//下载视频方法
private static void getDondow(String url,String pathName)throws Exception{
URL ul = new URL(url);
HttpURLConnection conn = (HttpURLConnection) ul.openConnection();
BufferedInputStream bi = new BufferedInputStream(conn.getInputStream());
FileOutputStream bs = new FileOutputStream(pathName);
System.out.println("文件大约:"+(conn.getContentLength()/1024)+"K");
byte[] by = new byte[1024];
int len = 0;
while((len=bi.read(by))!=-1){
bs.write(by,0,len);
}
bs.close();
bi.close();
}
}