3 Replies Latest reply: Dec 23, 2009 2:15 PM by 800421 RSS

    Get file name of running file

    800421
      I simply want to know what is the filename of the running file
      i.e.
      String findFileName(){
      //return this program's file name somehow
      }
      If you are wondering why do I want to know this, then here you are:
      I'm making a feature for downloading the latest version of the application and then replacing the old version with the new one.
      Any help?
        • 1. Re: Get file name of running file
          807580
          No need to re-invent the wheel. Google for JNLP or WebStart.
          • 2. Re: Get file name of running file
            807580
            MariusGav wrote:
            I'm making a feature for downloading the latest version of the application and then replacing the old version with the new one.
            Do you mean just like java web start? Perhaps you should look at how this works and either use it or learn from it.
            I simply want to know what is the filename of the running file
            Is that the class file, the jar file or the source file? Files don't run. Threads run code in class methods.
            If you are wondering why do I want to know this, then here you are:
            You can try
            URL urlForThisClass = getClass().getProtectionDomain().getCodeSource().getLocation();
            • 3. Re: Get file name of running file
              800421
              With file I was referring to the jar.
              I've tried
              URL urlForThisClass = getClass().getProtectionDomain().getCodeSource().getLocation();
              and it works perfectly. Thanks a lot