7 Sept 2012

Downloading jar file in java source code


URL url = new URL("http://...sources.jar");  
InputStream inStream = url.openStream();  
System.out.println(inStream.available());  
BufferedInputStream bufIn = new BufferedInputStream(inStream);  
              
File fileWrite = new File("outputsrc.jar");  
    OutputStream out= new FileOutputStream(fileWrite);  
    BufferedOutputStream bufOut = new BufferedOutputStream(out);  
                    byte buffer[] = new byte[BUFFER_SIZE];  
            while (true) {  
int nRead = bufIn.read(buffer, 0, buffer.length);  
if (nRead <= 0)  
  break;  
bufOut.write(buffer, 0, nRead);  
        }  
              
            bufOut.flush();  
            out.close();  
            inStream.close();

0 comments:

Post a Comment