客户端程序需要从服务器下载文件,通过HTTP的,不是JSP,请问要怎么实现啊?最好提供一下代码,谢谢!!!

解决方案 »

  1.   

    你需要下载的,不属于标准JDK
    http://blog.alsox.com/article_189/
    这篇文章可能对你有用
      

  2.   

    BufferedInputStream br = null;
    HttpURLConnection connection = null;            
    URL url = new URL(path);
    connection = (HttpURLConnection) url.openConnection();
    br = new BufferedInputStream(connection.getInputStream());
    byte[] buffer = new byte[connection.getContentLength()+1];
    br.read(buffer);
                    if (br != null) {
                        br.close();
                        br = null;
                    }
                    if (connection != null) {
                        connection.disconnect();
                        connection = null;
                    }
      

  3.   

    import java.net.*;
    import java.io.*;public class ReadURL3 {
        public static void main(String argv[]) throws Exception {
            URL url = new URL("http://localhost:8080/images/logo.gif");
    //        URL url = new URL("http://localhost:8080/css/default.css");        BufferedInputStream in
                = new BufferedInputStream(url.openStream());
            BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream("f:\\temp\\mylogo.gif"));        int r;
            while ((r = in.read()) != -1) {
                out.write(r);
            }
            in.close();
            out.close();    }
    }