Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

what I'm asking is how to make any associated file type open my program with the corresponding data. For example, if you have a .doc file it opens Microsoft word with whatever is saved to that file. I know how to associate the file extension to my program, but it just opens the program from the location of the file. How do I make the program read the file upon start-up?

share|improve this question

migrated from Jan 8 '13 at 2:10

This question came from our site for professional and enthusiast programmers.

You make the program accept command-line arguments. When you open something from Explorer, it passes the name(s) of the item(s) you clicked on as command-line arguments. Your program must take these command-line arguments and do whatever processing is required... including opening and reading the contents.

In C/C++, these are the argc and argv arguments in int main(int argc, char *argv[]). In Java, it's the args in public static void main(String[] args). In other languages, you'll have to look into it.

share|improve this answer
So I start my method using my file loading method where args[0] is the name if the file? – Squirvin Jan 8 '13 at 0:33
One more thing, when I open the program with an associated file type, I get a dialog error window titled "Java Virtual Machine Launcher" and it says "A Java Exception has occurred." Why is that? – Squirvin Jan 8 '13 at 0:43

Since this is Java and a desktop app., the obvious solution would be Java Web Start.

JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..

Here is a demo. of the file services that associates the type .zzz with the demo. Double click such a file and it will open in the app.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.