I am running a java application from a jar file. How can I get the size of that file?
I don't think you can ... reliably1. The closest you can come is:
Find and parse the program's classpath as described here: https://stackoverflow.com/a/17541055/139985
Identify the classpath component that is the JAR file.
Use File.length()
on that file.
The problems are that you may not be able to identify the JAR file from the list, and the file may no longer be there ... depending on how you launched the JVM. Furthermore, the technique doesn't work if you dynamically run the application; i.e. using a classloader that your launcher creates on the fly in Java code in the same JVM.
Also, how can I get the size of a file from the internet without actually downloading it?
Once again, there's no totally reliable way1 to do this. You can attempt to extract the "content-length" header from the HTTP response ... before you start reading the response content. The problem is that "content-length" is optional, and there are situations where an HTTP server will not (or even cannot) provide it.
If you know that the server can give you the content length, then sending a HEAD request rather than a GET request will give you just the response header.
Also, how would this work in the IDE where there is no jar file?
I don't think it is practical.
Eventually, I am just going to download the files if they are different sizes, i.e. creating an auto update.
As others have mentioned, Java Web Start is the way to go. Don't attempt to roll your own scheme. For a start Java Web Start deals with a whole bunch of important security related concerns that would be difficult for you to do ... properly.
1 - What I mean is that the Java application has to make assumptions about other things. For instance, assumptions about the application launcher, and the server that is providing the JAR files.