I am coding a JAVA reader to read .txt files as a substitution for notepad. Now, the problem is, I want to set that program to be the default program to open all .txt files. Now, how the program will distinguish which file I am opening via the program? I don't want to make a program that will first open JFileChooser and will make the user to open that file via JFileChooser. I just want to make a notepad in java that will open .txt files like notepad does. When I will click on a file say, *.txt, it will use my program to open that file and my program will show the chars of that file.

有帮助吗?

解决方案

I didn't test it, but I would expect that if you create a Jar file from your sources, and you let your OS point to that file to open *.txt files, then the absolute path of the file to open would be in your main's "String[] args". Can you make a quick test?

其他提示

Surely the issue here is making Windows/OSX/Linux register your program as the default which presumably has to happen outside the confines of your program?

You can do an "Open with..." on Windows/Mac (not sure on Linux) and just use your program instead. Your program then could take the file name as the command line argument and do with it what you want.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top