在Java中暂停下载?
问题描述:
我使用这个代码来下载一个文件,我想知道,如果它可以暂停下载,然后在稍后恢复,如果又如何?:在Java中暂停下载?
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();
答
我认为对于简历的支持在服务器端,客户端不能指挥它。
答
这是,如果服务器支持HTTP范围报头(在HTTP 1.1中引入)仅可能
查看在Java示例这样一个问题:how to use the HTTP range header in J2ME?。
“暂停”可能意味着读取一些流并将其写入磁盘。恢复时,您必须使用标题指定要下载的内容。