Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7651171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:26:26+00:00 2026-05-31T11:26:26+00:00

I have recently been trying to create an updater for my program. The updater

  • 0

I have recently been trying to create an updater for my program. The updater is supposed to go to dropbox, look through the files in the ‘public’ folder, and decide if it exists. It works, and can DOWNLOAD the file, but it can’t CHECK if the file exists. I saw this and I thought it was a solution, but it doesn’t seem to be working.

Here is the code I’m using to check for the file’s existence:

public static boolean exists(String URLName) {
    try {
        HttpURLConnection.setFollowRedirects(false);
        HttpURLConnection con = (HttpURLConnection) new URL(URLName)
                .openConnection();
        con.setRequestMethod("HEAD");

        return (con.getResponseCode() == HttpURLConnection.HTTP_OK);

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

However, it seems to always return true. The files I’m accessing all begin with “App_” and end with “.zip”. The only thing that varies is the version, which is in the #.### format.

Here is the FULL code for how I’m checking it:

    public static void main(String[] args) throws IOException,
            InterruptedException {

        double origVersion = 0.008;

        double versionTimes = 0.000;
        while(exists("http://dl.dropbox.com/u/.../" + "App_"+ String.valueOf(origVersion + versionTimes) + ".zip")) {
            versionTimes = round(versionTimes + 0.001);
            //origVersion = round(origVersion + 0.001);


            System.exit(0);

    }
    }
public static boolean exists(String URLName) {
        try {
            HttpURLConnection.setFollowRedirects(false);
            // note : you may also need
            // HttpURLConnection.setInstanceFollowRedirects(false)
            HttpURLConnection con = (HttpURLConnection) new URL(URLName)
                    .openConnection();
            con.setRequestMethod("HEAD");

            return (con.getResponseCode() == HttpURLConnection.HTTP_OK);

        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    static double round(double d) {
        DecimalFormat twoDForm = new DecimalFormat("#.###");
        return Double.valueOf(twoDForm.format(d));
    }

Sorry about that… That code was too long. Anyway. To test this, right now it will check if version 0.009 is available. Which it is. Its full version is in the variable double origVersion. Now, if you set origVersion to 0.009, it will check for 0.01. Which is fine, except for the fact that App_0.01.zip DOES NOT exist, and yet it still says it does!

I have also looked into wget to solve this problem, by starting up wget with the arguments

THEFILENAME –no-proxy –spider

but that didn’t work either. Can anyone help me? I would greatly appreciate it.

I also saw somewhere else that you could establish a connection with the file and if it secures, the file exists. If not, it doesn’t. However, I have no idea how to do that. Can anyone bring me out of the dark?

[EDIT]

Also, running the THEFILENAME –no-proxy –spider on wget worked, and outputted the following, when checking for version 0.009:

Spider mode enabled. Check if remote file exists.
--2012-03-16 08:59:55--  http://dl.dropbox.com/u/.../....zip
Resolving dl.dropbox.com... 107.21.103.249, 107.20.135.4, 107.20.198.68, ...
Connecting to dl.dropbox.com|107.21.103.249|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 758067 (740K) [application/zip]
Remote file exists.

And when checking for version 0.01:

Spider mode enabled. Check if remote file exists.
--2012-03-16 09:01:15--  http://dl.dropbox.com/u/.../....zip
Resolving dl.dropbox.com... 107.22.196.64, 50.19.217.32, 174.129.218.194, ...
Connecting to dl.dropbox.com|107.22.196.64|:80... connected.
HTTP request sent, awaiting response... 404 NOT FOUND
Remote file does not exist -- broken link!!!

I also tried reading the output of wget using this, and using if(input.indexOf(“404 NOT FOUND”) == -1), but still to no avail.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:26:27+00:00Added an answer on May 31, 2026 at 11:26 am

    Doing a HEAD request is definitely the right way to check if a file exists on a remote server.

    I can’t see anything wrong with your exists(String URLName) method so I would check that it is being passed the URL you think it is.

    What looks odd to be is this line:

    versionTimes = round(versionTimes + 0.001);
    

    You’re changing the value of versionTimes in between checking for the existence of the file and printing your message.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently been trying to port a C++ application. I believe I have all
recently I've been trying to create pseudo-AciveRecord-style db calls in my android app and
I'm a vim user and have recently been trying out emacs for fun. I
I've recently been using Angularjs in my project. I'm trying to create a dynamic
recently I been trying to create an android app that uses JSON Objects to
Recently, I have been trying to accomplish creating a full-width jQuery slider that would
I've been trying to create a transparent table view recently but I'm not having
Recently I have been working with a SQL Server database and I was trying
I have recently begun the process of trying to learn Ruby/Rails and have been
I have recently been using WxPython to create a GUI Network simulator like Cisco

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.