Source Code : Read a GIF or CLASS from an URL save it locally

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Read a GIF or CLASS from an URL save it locally

      
import java.io.DataInputStream;
import java.io.FileOutputStream;
import java.net.URL;
import java.net.URLConnection;

public class Main {
  public static void main(String args[]) throws Exception {
    byte[] b = new byte[1];
    URL url = new URL("http://www.server.com/a.gif");
    URLConnection urlConnection = url.openConnection();
    urlConnection.connect();
    DataInputStream di = new DataInputStream(urlConnection.getInputStream());

    FileOutputStream fo = new FileOutputStream("a.gif");
    while (-1 != di.read(b, 0, 1))
      fo.write(b, 0, 1);
    di.close();
    fo.close();
  }
}

   
    
    
    
    
    
  

Thank with us