I have a basic, simple and maybe stupid question, but how do I implement that I can drag a file onto my java program and open it? I searched really long for this basic question.....
As long as I found out you can't implement dragging it onto the .jar, because its not executable. You have to create a .exe, which also open your .jar, but that's all! I would really like to know how :)
A keyword would be enough, if I can get the answer through searching this keyword.
Thanks, Leander
//Edit: I may have expressed things a little bit complicated. Later i want to have a shortcut on, for example, the desktop where i can drag any file on the shortcut and the programm opens with the file(it will, at this point) only move it to a special location.
I don´t know how the code for this would be, I even don't know how to google for this (I only get questions how to implement "open with" with the answer Desktop.open(File f)).
For windows only:
option 1:
make a batch file into the directory of your jar file (or anywhere you like but then you need to adjust the path, you can also make a shortcut from the batch file).
@ECHO OFF
start java -jar %~dp0MYAPP.jar %1
option 2:
drag and drop will work if your jar accepts filename as a parameter
public class Main {
public static void main(String[] args) {
if (args.length == 0)
System.out.println("No arguments");
else
System.out.println("1st argument: " + args[0]);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With