Jump to content
  • Advertisement
Sign in to follow this  
Thoover

[java] Java Downloader/updater

This topic is 3899 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok i get get pure text like html easily off the internet with :
void getUrlFile(String s, String sn) throws MalformedURLException
	{
		URL url = new URL(s);
		StringBuffer stringbuffer = new StringBuffer();
		try
		{
			FileWriter filewriter = new FileWriter(sn);
			BufferedWriter bufferedwriter = new BufferedWriter(filewriter);
			HttpURLConnection httpurlconnection = (HttpURLConnection)url.openConnection();
			httpurlconnection.connect();
			InputStreamReader inputstreamreader = new InputStreamReader((InputStream)httpurlconnection.getContent());
			BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
			String s1;
			do
			{
				s1 = bufferedreader.readLine();
				if(s1 == null)
				s1 = "\n";
				stringbuffer.append((new StringBuilder()).append(s1).append("\n").toString());
				bufferedwriter.write((new StringBuilder()).append(s1).append("\n").toString());
			} while(s1 != "\n");
			bufferedwriter.close();
		}
		catch(IOException ioexception)
		{
		}
	}

but i am wondering how i get a binary file like images exes jars zips etc so i can make an install program and an auto update (becouse i have to face the fact that the user does not want to download my programs for every update i make [which is about 2 times a day at the moment] )

Share this post


Link to post
Share on other sites
Advertisement
Have you tried using Java Webstart?

It solves all versioning, deployment, installation problems...

Supporting full HTTP protocol isn't trivial, you're probably best off finding a library that supports it. It might exist in standard Java, but I can't recall it right now.

Share this post


Link to post
Share on other sites
You should use Web Start if you can. If you can't, put all your updates in a single zip and use Java's built in zip support(java.util.zip.* package). You just wrap your stream in a ZipInputStream and the zip package handles all the messy details.

Share this post


Link to post
Share on other sites
Heyas

Most guys have told you to use webstart and most guys will tell you to use webstart.
I would say that in this particular case webstart would probably be easier.


Regardless:

You already know how to download everything.
Basic way is to open a stream from an URL and read each byte, then save that stream wherever. Doesnt make a difference whether its an image, text or anything else.

Best way is to compress your files within a zip or jar then open this using a ZipInputStream. This will allow you to quickly download any files you want since you only have to specify one file and then you download anything inside the specified file (as opposed to using a large list of files to download).

Hope this is helpful.
Yours Truly
K

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!