Sign in to follow this  

[java] Java Downloader/updater

This topic is 3587 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
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

This topic is 3587 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this