How can I open file with my self made program from Windows.

It’s not too hard to make it possible to open a file inside my self made program but how can I make my program to open a file (and my program and show the file inside my program after it’s launched) right-clicking a file on my desktop and choosing open in application (I don’t have english version of Windows so I don’t remember how that function is named excactly) and choosing the program and it opens that file with my own program.

For example you can open an image with mspaint by clicking it with your right mouse button --> choose “Open in application” (or whatever) --> click “Paint” and now Paint is executed and image is open inside it.

I think I could probably code a program similar to mspaint with java without bigger problems except this. :frowning: I guess I should send the path of the file as a parameter when excecuting my program or something. ???

http://www.devx.com/tips/Tip/13867

No, those explain how to load an external program from within Java; by my reading, the question ws about how to associate a Java application in Windows with certain types of files.

Which, off the top of my head, I’m not sure about, but I’m sure someone knows.

If I’m misinterpreting, and the question is about how to get the file name passed in when you “Open with…”, I’m pretty sure it’s saved in the args array that main gets passed, as the first entry.

You can do it using jnlp files/webstart:

put this inside the information tag:

This will associate files that end in ‘bsh’ with your program.

See the jnlp file i use here: http://www.freewebs.com/commanderkeith/SlaveBot/SlaveBot.jnlp

Good luck!

Thanks for help. Link didn’t work now but I’ll try again later.

I can’t say who understood my problem and who didn’t so I’ll look into those links what Cyan gave and see if these are helpful.

Anyway thanks to all. :slight_smile:

Edited and added later:

I quickly read those links and these didn’t solve the problem because, as ewjordan said, I am not loading external program with java. I want to open a file, for instance, from my desktop with my self made program.

I guess this jnlp (that I have never needed and understood) that CommanderKeith mentioned might be a solution.

Just out of curiosity, is there some way to do it without Java Webstart? It seems like there should be.

just use the
“String args[]” in the main function to open the file from within your program

in order to open your file through windows as default in Windows XP:

  1. in an explorer window, goto tools->folder options
  2. then click on the “file types” tab
  3. select “New”, type in your file types extension
  4. select your new file type from the list, and click advanced
  5. from there you should be able to setup the execution of your program.
  6. then add (I think) “%1” at the end of it

this should make more sense if you spend some time looking through other programs. in your file types browser.

if you would like to make a simple install version, you could also save the regestry version. so that other users may double click to install the new fileType, or run the .reg file from within your own install program.

Yarr, I’m too stupid for this.

However I overcame this issue switching Java to C++. Now I was able to send those cmdline parameters to my program easily.

I guess Java is not my thing because I have been able to resolve some other issues too with C++ that I couldn’t resolve with Java, even though I have coded over 2 years with Java and only about 2 months with C++. :-\

the “String args[]” in the java main() function.
Is were the location of the command line Strings are storred.
Its very similar to the way C++ console apps use command line arguements.

All I know is that I made application with Java and similar with C++ and both take commandline arguments but only c++ application can take my text files path from my desktop when I right click the text file on my desktop and choose my application.

I guess my problem is actually that my java application is jar and I guess I must send the string some how differently to it than in normal case. I guess I must drink some coffee tonight and resolve it with java too and I don’t need to think about this anymore and move on. :slight_smile: