After making an installer to my app, I can make it associate with a file extension, which is great, but I can't figure out how can I detect the path of the file that my program was opened with. Any help is appreciated!
Asked
Active
Viewed 60 times
2
-
3I think it's passed as a command line argument to `main(...)` (and is available via `getParameters()` in the `Application` subclass). – James_D Sep 22 '21 at 12:43
-
https://stackoverflow.com/questions/35679904/get-the-args-in-application-launchclass-string-args/35693825 – Joop Eggen Sep 22 '21 at 12:44
-
Also see: [How to get the current working directory in Java?](https://stackoverflow.com/questions/4871051/how-to-get-the-current-working-directory-in-java), similarly for the [user home directory](https://stackoverflow.com/questions/585534/what-is-the-best-way-to-find-the-users-home-directory-in-java/586345), and there is also [`java.class.path`](https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html): in case any of those are actually what you really need. – jewelsea Sep 22 '21 at 21:20
1 Answers
3
For anyone having this problem, the file path is the first argument in getParameters().getRaw()
Javadoc description of the function.
Retrieves a read-only list of the raw arguments. This list may be empty, but is never null. In the case of a standalone application, it is the ordered list of arguments specified on the command line. For named parameters, each <name,value> pair is represented as a single argument of the form: "--name=value".
Thanks, James_D!