2011-10-01 90 views
0

我使用這個代碼來下載一個文件,我想知道,如果它可以暫停下載,然後在稍後恢復,如果又如何?:在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(); 

回答

0

我認爲對於簡歷的支持在服務器端,客戶端不能指揮它。

4

這是,如果服務器支持HTTP範圍報頭(在HTTP 1.1中引入)僅可能

查看在Java示例這樣一個問題:how to use the HTTP range header in J2ME?

「暫停」可能意味着讀取一些流並將其寫入磁盤。恢復時,您必須使用標題指定要下載的內容。