本文主要是介绍http的断点传送,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
http的断点传送使用range来设置
代码:
package cn.itcast.http;import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;public class RangeDemo {/*** @param args*/public static void main(String[] args) throws Exception{URL url = new URL("http://localhost:8080/WebProject1/1.txt");HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setRequestProperty("Range", "bytes=5-");InputStream in = conn.getInputStream();FileOutputStream out = new FileOutputStream("c:\\1.txt",true);byte[] buffer = new byte[1024];while(in.read(buffer)>0){out.write(buffer, 0, buffer.length);}}}
出现Server returned HTTP response code: 416 for URL: http://localhost:8080/WebProject1/1.txt错误,是由于conn.setRequsetRroperty("Range","bytes=5-");设置错误
这篇关于http的断点传送的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!