java监听exe程序,侦听“使用我的Java应用程序打开文件” Windows事件

Title is confusing, but don't know how to explain this in a few words:

I have a java application that reads *.example files. I've also added a file association thanks to install4j so my application is launched when the user double clicks any file with extension *.example

It seems that install4j sends the file path in the args[] so it should be easy to open that file and show it in my app. BUT what happens if the app is already running? I can only allow one instance of the application so, how can I know that the user is opening a file?

But I still don't understand how should I use it and what should I add in my app to listen for this event. Where can I find an example?

解决方案

Based on the documentation you linked to, it looks like you can do this:

StartupNotification.registerStartupListener(new StartupNotification.Listener() {

public void startupPerformed(String parameters) {

System.out.println("Startup performed with parameters " + parameters);

}

});

Since startupPerformed will be called from different threads, you will need to make sure that the code that handles these notifications is thread-safe.

The documentation also says:

For multiple files, files are surrounded by double-quotes and separated by spaces.

So you will need to parse the parameter string yourself as well.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值