自己写程序用就是爽啊
今天在网上找到了《越狱》的看美剧学英语的听力讲解课堂(www.tingclass.net),有70多节课,而且还有lrc文件。试听了一些搅得的挺好的,就打算下载下来,可是发现可以批量下载,但是没有lrc文件,lrc文件得一个一个的下载,我去,这不扯淡了吗!
后来我发现lrc的文件下载地址有规律啊:
第一节:http://down11.tingclass.net/textrar/lesson/0001/1167/1.lrc
第二节:http://down11.tingclass.net/textrar/lesson/0001/1167/2.lrc
所以就想到用java写一个程序来帮我批量下载lrc文件。于是就写了一段程序,开始执行,结果几十个文件瞬间就搞定了!真是爽呆了啊!
晒一下代码,呵呵:
package com.match.test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class DownTheNetLrcFile {
private static final String URL = "http://down11.tingclass.net/textrar/lesson/0001/1167/";
public static void main(String[] str){
new DownTheNetLrcFile().start();
}
private void start() {
for(int i = 8;i < 62;i++){
downloadFile(i);
}
}
private void downloadFile(int i) {
String urladress = URL + i +".lrc";//http://down11.tingclass.net/textrar/lesson/0001/1167/7.lrc
try {
URL url = new URL(urladress);
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
File f = new File("C:\\Users\\Administrator\\Desktop\\d\\"+i+".lrc");
FileOutputStream fos = new FileOutputStream(f);
byte[] buffer = new byte[1024];
int len = 0;
while((len = is.read(buffer)) != -1){
fos.write(buffer, 0, len);
}
fos.flush();
fos.close();
is.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}