请问几个问题:
1。用Socket实现ftp和http的下载,用
Socket s;
//init Socket there
BufferedReader reader = new BufferedReader(
new InputStreamReader(s.getInputStream())
);
从reader中读取Http的head(需要用到readLine())然后怎么样通过stream读入数据。继续用reader读可以吗? 2。用URL、URLConnection、HttpURLConnection怎么实现Http、和Ftp下载,我需要对其有更多的控制,比如说断点续传,怎么构造自己的FtpURLConnection; 3。有没有对java.net.*包中的设计模式介绍/详述的资料。
1。用Socket实现ftp和http的下载,用
Socket s;
//init Socket there
BufferedReader reader = new BufferedReader(
new InputStreamReader(s.getInputStream())
);
从reader中读取Http的head(需要用到readLine())然后怎么样通过stream读入数据。继续用reader读可以吗? 2。用URL、URLConnection、HttpURLConnection怎么实现Http、和Ftp下载,我需要对其有更多的控制,比如说断点续传,怎么构造自己的FtpURLConnection; 3。有没有对java.net.*包中的设计模式介绍/详述的资料。
String filepro = sr.substring( (sr.length()-3) );
response.setContentType( "application/" + filepro ); // MIME type for pdf doc
response.setHeader("Content-disposition",
"attachment; filename=" + "my.doc");
String fileURL = sr;
URL url=new URL(fileURL);
BufferedInputStream bis = new BufferedInputStream(url.openStream());
BufferedOutputStream bos = new BufferedOutputStream( response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while (-1!=(bytesRead=(bis.read(buff,0,buff.length)))){
bos.write(buff,0,bytesRead);
}
if (bis!=null){
bis.close();
}
if (bos!=null){
bos.close();
}