首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

httpclient写文件下载程序,该怎么解决

2012-01-11 
httpclient写文件下载程序想下载http://202.120.96.77/dataViewPage/getView.aspx?codeidY1里的pdf文件总

httpclient写文件下载程序
想下载http://202.120.96.77/dataViewPage/getView.aspx?codeid=Y1里的pdf文件
总是不成功,哪位大哥帮改改

Java code
import org.apache.commons.httpclient.HttpClient;import org.apache.commons.httpclient.HttpException;import org.apache.commons.httpclient.methods.PostMethod;public class HttpClientTest {    private final static String REMOTE_FILE_URL = "http://202.120.96.77/dataViewPage/getFile.aspx?filename=GB-T 1.1-2000.pdf";    private final static int BUFFER = 1024;    public static void main(String[] args) {        HttpClient client = new HttpClient();        PostMethod httpGet = new PostMethod(REMOTE_FILE_URL);        try {            client.executeMethod(httpGet);            InputStream in = httpGet.getResponseBodyAsStream();                        FileOutputStream out = new FileOutputStream(new File("E:\\GB-T 1.1-2000.pdf"));            byte[] b = new byte[BUFFER];            int len = 0;            while ((len = in.read(b)) != -1) {                out.write(b, 0, len);            }            in.close();            out.close();        } catch (HttpException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        } finally {            httpGet.releaseConnection();        }        System.out.println("download, success!!");    }}


[解决办法]
绑定,给分
[解决办法]
Java code
public static void main(String[] args) {        HttpClient client = new HttpClient();        PostMethod httpGet = new PostMethod(REMOTE_FILE_URL);        try {            client.executeMethod(httpGet);            InputStream in = httpGet.getResponseBodyAsStream();                        FileOutputStream out = new FileOutputStream(new File("E:\\GB-T 1.1-2000.pdf"));            byte[] b = new byte[BUFFER];            int len = 0;            while ((len = in.read(b)) != -1) {                out.write(b, 0, len);                out.flush();//注意要清空流            }        } catch (HttpException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        } finally {            try{             in.close();            }catch(Exception e){             e.printStackTrace();            }            try{             out.close();            }catch(Exception e){             e.printStackTrace();            }                        httpGet.releaseConnection();        }        System.out.println("download, success!!");    }
[解决办法]
探讨
out.flush();//注意要清空流

[解决办法]
学习。。。
[解决办法]
java + js

热点排行