Java用户启动程序与文件启动程序

时间:2021-11-24 00:04:37

I'm making a program that will be run in Windows and to open a custom file type with it. I know how to associate the file type with the program, but is there a way to tell whether the program was opened by the user (blank screen when opened, no content visible) or whether the program was started by opening a file associated with the program (double click file and it start the program so the content in the file is visible)?

我正在制作一个将在Windows中运行的程序,并用它打开自定义文件类型。我知道如何将文件类型与程序相关联,但有没有办法判断程序是否由用户打开(打开时为空白屏幕,没有可见内容),或者是否通过打开与程序(双击文件,它启动程序,以便文件中的内容可见)?

1 个解决方案

#1


1  

When you define your static void main(String[] args) method, the args is actually the command-line arguments to your program.

当您定义静态void main(String [] args)方法时,args实际上是程序的命令行参数。

If there are no arguments, it was opened by itself, but if there are any arguments (specifically, you are interested in just the first), then it was most likely started by double-clicking on a file associated with your program, and that first argument will then be the full path to the file.

如果没有参数,它本身是打开的,但是如果有任何参数(具体来说,你只对第一个感兴趣),那么很可能是通过双击与你的程序相关的文件开始的,然后,第一个参数将成为文件的完整路径。

#1


1  

When you define your static void main(String[] args) method, the args is actually the command-line arguments to your program.

当您定义静态void main(String [] args)方法时,args实际上是程序的命令行参数。

If there are no arguments, it was opened by itself, but if there are any arguments (specifically, you are interested in just the first), then it was most likely started by double-clicking on a file associated with your program, and that first argument will then be the full path to the file.

如果没有参数,它本身是打开的,但是如果有任何参数(具体来说,你只对第一个感兴趣),那么很可能是通过双击与你的程序相关的文件开始的,然后,第一个参数将成为文件的完整路径。