简体   繁体   中英

How do I open a file with a jar file?

I'm not trying to open a file once my program has run, ex. Using Desktop.open, I'm trying to make it so I can right-click a file, and choose "Open-with" and then choose my application. I then want the path to the file being opened to be passed as one of the args to my application. This could allow me to make, for example, a text editor, and not have to run the client program in order to run other files that it handles.

If you click on a file and choose open with you should already be able to choose your application. Maybe it does not occoure in the list of suggested application but you could browse for it and it should start.

I dont know how it works on a linux system but on a windows system you get the file path into your application. The following example will print the path of the file you have opened with "open with":

public static void main(String[] args) { 
     System.out.println(args[0]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM