暂停Java下载?

时间:2011-10-01 10:46:42

标签: java download

我正在使用此代码下载文件,我想知道是否有可能暂停下载然后稍后恢复,如果是这样的话:?

    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();

2 个答案:

答案 0 :(得分:4)

仅当服务器支持HTTP范围标头(在HTTP 1.1中引入)

时,才可以执行此操作

请参阅此问题以获取Java中的示例:how to use the HTTP range header in J2ME?

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

答案 1 :(得分:0)

我认为对简历的支持是在服务器端,客户端无法指导它。