Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 18 of 18

Thread: Updater Project: Download and Execute Update

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Updater Project: Download and Execute Update

    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);
      }
      }
       }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Updater Project: Download and Execute Update

    it renames the update or something and corrupts the '.jar'.
    I don't think renaming a file will change its contents.
    Can you explain what happens? "or something" doesn't say much.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Updater Project: Download and Execute Update

    Well when I run it the file is downloaded and placed on the desktop but is somehow corrupt and not executable.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Updater Project: Download and Execute Update

    Do you have a compare program that can compare files byte by byte and find what has been corrupted?
    I assume you have checked to see if the files are exactly the same size.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Updater Project: Download and Execute Update

    No they aren't the same size. I'm not sure why.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Updater Project: Download and Execute Update

    Try debugging the code by adding println statements that print out the number of bytes read. Also sum them and print the running total of all the bytes read.

    Did you compare the bytes that were there? Did they match?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Updater Project: Download and Execute Update

    Truthfully I'm very new to this and I don't exactly know how to do this...

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Updater Project: Download and Execute Update

    What part is the problem? The code uses println statements already
    numRead contains the number of bytes read, print it using println()
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Updater Project: Download and Execute Update

    Where exactly would I put this statement? At the end of the 'download' method?

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Updater Project: Download and Execute Update

    Open the file that was downloaded in a text editor and see what it there.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Updater Project: Download and Execute Update

    -nevermind.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Updater Project: Download and Execute Update

    what did you see in the downloaded file?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Updater Project: Download and Execute Update

    For some reason it downloaded the webpage and converted it from a '.html' file to a '.jar' file.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Updater Project: Download and Execute Update

    converted it from a '.html' file to a '.jar' file.
    There was no conversion. Your program wrote what it received from the server into a file with a .jar extension.

    What message did the html file have?
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Updater Project: Download and Execute Update

    <!DOCTYPE html>
    <html>
    	<head>
    		<title>wBot download</title>
    		<meta name="keywords" content="runescape, bot, runescape bot, runescape hd bot, runescape 2007, runescape mmo, runescape 2007 bot, rs 2007, rs 2007 bot"/>
    		<meta name="description" content="wBot - For the best bot experience in oldschool RuneScape 2007.  The First Runescape 2007 bot out!"/>
    		<link rel="stylesheet" href="/includes/style.css" type="text/css" />
    		<script type="text/javascript">
    		  var _gaq = _gaq || [];
    		  _gaq.push(['_setAccount', 'UA-33446437-1']);
    		  _gaq.push(['_trackPageview']);
     
    		  (function() {
    		    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    		    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    		    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    		  })();
    		</script>
    		<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    	</head>
    	<body>
    		<div id="header">
    			<table width="100%" style="max-width:1024px; margin: 0 auto;">
    				<tr>
    					<td>
    						<a href="index.php"><img src="http://wbot.nl/wbot.png" style="height:75px;"></a>
    					</td>
    					<td align="center" style="color:white;">
    					</td>
    					<td align="right">
    						<a href="http://wbot.nl/community/irc.php" style="color:white; font-size:16px">Chat in the IRC channel</a><br><br>
     
    						<a href="https://twitter.com/official_wBot" class="twitter-follow-button" data-show-count="false" data-size="large">Follow @2006scapebot</a>
    						<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
    					</td>
    				</tr>
    			</table>
    		</div>
    		<div id="menu">
    			<div id="menu_content">
    				<span class="link"><a href="/community/index.php">Community</a></span>
    				<span class="link "><a href="/repository/index.php">Scripts</a></span>
    				<span class="link open"><a href="/download/index.php">Download</a></span>
    				<span class="link "><a href="/subscription/index.php">Subscriptions</a></span>
     
    				<div class="right">
    											<span class="link"><a href="/community/ucp.php?mode=register">Register</a></span>
    						<span class="link"><a href="/community/ucp.php?mode=login">Login</a></span>
    										</div>
    			</div>
    		</div>
    		<div id="container" style="margin:0 auto; max-width:1024px">
    			<div id="content">You need to login on the forums before downloading wBot.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Updater Project: Download and Execute Update

    You need to login on the forums before downloading wBot.
    This seems to be the important part.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Updater Project: Download and Execute Update

    Yeah, I'm asking the forum moderator to make me a direct link so I can get it done. Do you think that the direct link will fix my problem?

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Updater Project: Download and Execute Update

    You will have to ask the site's administrator to see how the server can be used.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. how to execute multiple different queries in one execute?
    By Sakina in forum JDBC & Databases
    Replies: 1
    Last Post: June 9th, 2012, 09:40 AM
  2. JAVA DOWNLOAD
    By sephskie in forum Java Theory & Questions
    Replies: 1
    Last Post: January 9th, 2012, 08:38 PM
  3. [SOLVED] Download a JAR from URL
    By bgroenks96 in forum Java Theory & Questions
    Replies: 2
    Last Post: July 9th, 2011, 10:02 AM
  4. Cache Download problem
    By frozen java in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 27th, 2011, 08:04 PM
  5. KB/s download speed calculating
    By Koâk in forum Java Theory & Questions
    Replies: 2
    Last Post: December 16th, 2009, 03:05 PM