如题,在线等

解决方案 »

  1.   

    java.net.URL,java.net.URLConnection,网上喳喳这两个类。从一个指定的url,用流的方式吧数据读过来就可以了
      

  2.   

    哪个高手帮忙写一下啊,我那样做就是出不来啊
    public class ReadGif { public static void getGif() throws Exception {

    String URLName = "http://www.baidu.com/img/logo.gif";
    int HttpResult;  
    URL url=new URL(URLName);  
    URLConnection urlconn=url.openConnection();  
    urlconn.connect();  
    HttpURLConnection httpconn=(HttpURLConnection)urlconn;  
    HttpResult=httpconn.getResponseCode();  

    if(HttpResult!=HttpURLConnection.HTTP_OK)  
    {  
    System.out.println("cant connct0");  
    }  
    else  
    {  
    int filesize=urlconn.getContentLength();  
    InputStreamReader isReader=new InputStreamReader(urlconn.getInputStream());  
    char[] buffer=new char[filesize];
    int num=0;  
    PrintWriter fileOut = new PrintWriter(new FileWriter("1.gif")); 
    String temp = "";
    //while(num>-1){  

    num=isReader.read(buffer);  
    //if(num<0)break; 
    try {
    fileOut.write(buffer, 0, num);
    } catch (Exception e) {
    System.out.println(e);
    }
    fileOut.close();

    //}  

    isReader.close();
    }
    } public static void main(String[] args) { try {
    ReadGif.getGif();
    } catch (Exception e) { } }}
      

  3.   

    package getpicture;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2005</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */
    import java.net.*;
    import java.io.*;
    import javax.imageio.*;
    import javax.imageio.stream.ImageOutputStream;public class GetPic {
      public GetPic() {
      }  public static void main(String[] args) {
        GetPic getPic1 = new GetPic();
        getPic1.saveToFile("http://community.csdn.net/images/CSDN_logo.GIF");
      }  public void saveToFile(String destUrl) {
        FileOutputStream fos = null;
        BufferedInputStream bis = null;
        HttpURLConnection httpUrl = null;
        URL url = null;
        int BUFFER_SIZE = 1024;    byte[] buf = new byte[BUFFER_SIZE];
        int size = 0;
        try {
          url = new URL(destUrl);
          httpUrl = (HttpURLConnection)url.openConnection();
          httpUrl.connect();
          bis = new BufferedInputStream(httpUrl.getInputStream());      fos = new FileOutputStream("e:\\haha.gif");
          while ((size = bis.read(buf)) != -1) {
            fos.write(buf, 0, size);
          }
          fos.flush();
        }
        catch (IOException e) {
        }
        catch (ClassCastException e) {
        }
        finally {
          try {
            fos.close();
            bis.close();
            httpUrl.disconnect();
          }
          catch (IOException e) {
          }
          catch (NullPointerException e) {
          }
        }
      }
    }