【问题标题】:Pause download in Java?在 Java 中暂停下载?
【发布时间】:2011-10-01 10:46:41
【问题描述】:

我正在使用此代码下载文件,我想知道是否可以暂停下载然后稍后恢复,如果可以,如何?:

    URL url = new URL(URL);
        URLConnection conexion = url.openConnection();

        conexion.connect();
        int lenghtOfFile = conexion.getContentLength();
        lenghtOfFile /= 100;

        InputStream input = new BufferedInputStream(url.openStream());
        OutputStream output = new FileOutputStream(Path + FileName);

        byte data[] = new byte[1024];
        long total = 0;

        int count = 0;
        while ((count = input.read(data)) != -1) {
            output.write(data, 0, count);
            total += count;
        }

        output.flush();
        output.close();
        input.close();

【问题讨论】:

    标签: java download


    【解决方案1】:

    这只有在服务器支持 HTTP 范围标头(在 HTTP 1.1 中引入)时才有可能

    有关 Java 示例,请参阅此问题:how to use the HTTP range header in J2ME?

    “暂停”可能只是意味着读取一些流并将其写入磁盘。恢复时,您必须使用标题来指定要下载的内容。

    【讨论】:

      【解决方案2】:

      我认为对简历的支持是在服务器端,客户端不能直接。

      【讨论】:

        猜你喜欢
        • 2011-01-03
        • 1970-01-01
        • 1970-01-01
        • 2011-02-24
        • 1970-01-01
        • 1970-01-01
        • 2018-06-25
        • 2011-08-06
        • 1970-01-01
        相关资源
        最近更新 更多