I've been working on this simple updater for a program called wbot for the past 2 days.
It downloads the update but it renames the update or something and corrupts the '.jar'.
Here's my code:
import java.applet.Applet; import java.io.BufferedOutputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; import java.net.URLConnection; import java.awt.*; import java.net.*; import java.io.*; public class Jar extends Applet{ public void paint(Graphics g) { //method to draw text on screen // String first, then x and y coordinate. g.drawString("It Works!",20,20); } public void init(){ // new dmw(); String userdir = System.getProperty("user.home") + "\\"+"Desktop"; String fpath = userdir.concat("\\wbot.jar"); System.out.println(fpath); final String locationDownload ="http://wbot.nl/download/index.php?download"; download(locationDownload, fpath); final Runtime run = Runtime.getRuntime(); try { run.exec(fpath); } catch (final IOException e) { System.out.println(e); } } public void download(final String address, final String localFileName) { OutputStream out = null; URLConnection conn = null; InputStream in = null; try { final URL url = new URL(address); out = new BufferedOutputStream(new FileOutputStream(localFileName)); conn = url.openConnection(); in = conn.getInputStream(); final byte[] buffer = new byte[1024]; int numRead; while ((numRead = in.read(buffer)) != -1) { out.write(buffer, 0, numRead); } } catch (final Exception exception) { System.out.println(exception); } finally { try { if (in != null) { in.close(); } if (out != null) { out.close(); } } catch (final IOException ioe) { System.out.println(ioe); } } } }