Catching Droped File On an application
Author |
Message |
copthesaint
|
Posted: Fri Nov 04, 2011 11:34 am Post subject: Catching Droped File On an application |
|
|
What I want to do is make a jar program that will startup when a file is dropped on the jar
for example textfile01.txt is moved and dropped on program.jar
I want 'program.jar' to then read the file.
Anyone know how I can do this?
I just want to read simple text. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
|
|
|
|
DemonWasp
|
Posted: Fri Nov 04, 2011 1:59 pm Post subject: RE:Catching Droped File On an application |
|
|
For Windows, I recommend this StackOverflow question: http://stackoverflow.com/questions/382878/launching-java-classes-via-windows-drag-and-drop
The easiest way seems to be creating a file Windows sees as an executable (a .bat, though you could also use a .exe or more obscure executable format) that passes those arguments to your Java program. Then you drag your arguments to program.bat, which calls your Java stuff.
There's also a registry hack, but that looks a little insane for something so trivial. |
|
|
|
|
|
Dan
|
Posted: Fri Nov 04, 2011 11:35 pm Post subject: RE:Catching Droped File On an application |
|
|
To add to what DemonWasp stated, on windows you can also acompish this with shortcuts if you make a shortcut to the java excutable and pass the arugments to run the jar. After that files droped on the shortcut should be passed as arugments.
However it would best to simply tell your users to pass the file as an arugment to the program as it would be the most portable soultion. If you want to make it more user friendly you could then make a GUI with a file browser which calls the application or look into APIs and event calls for when a file is droped on an active application's GUI (as Tony mentioned, tho almost all desktop enviroments support this in some way). |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
copthesaint
|
Posted: Wed Nov 09, 2011 9:18 am Post subject: RE:Catching Droped File On an application |
|
|
kk thanks both of you. |
|
|
|
|
|
|
|