现在的位置: 首页 > 综合 > 正文

android 随手记 下载url里的数据

2018年09月15日 ⁄ 综合 ⁄ 共 1140字 ⁄ 字号 评论关闭

import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class TestGetVideoInfo {

    /**
     * @param args
     */
    public static void main(String[] args) {
        TestGetVideoInfo getvideoinfo = new TestGetVideoInfo();

        String url = "http://cdn.52itv.cn/?data=list&tid=1&item=&area=&year=&top=&page=&num=4815";
        try {
            getvideoinfo.download_list(url);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private void download_list(String url) throws IOException {
        URL website = new URL(url);
        ReadableByteChannel rbc = Channels.newChannel(website.openStream());

        String newfilename = url.replace("http://cdn.52itv.cn/?", "");
        FileOutputStream fos = new FileOutputStream("/home/yulin724/tmp/"
                + newfilename);
        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
        fos.close();

    }

}

抱歉!评论已关闭.