如何将文件与Java中的程序相关联 [英] How to associate a file with a program in java

查看:154
本文介绍了如何将文件与Java中的程序相关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以记事本为例。您可以使用记事本打开文件(右键单击并打开,或双击文件,如果它已经与记事本相关联),它将显示文件的内容。我想要能够打开一个xml文件与我写的程序,以便它可以做一些解析和给出所需的输出。在Java中有什么方法来做到这一点?在打开程序时,我必须要求一个参数传递给程序吗?这将更容易在C + +或其他语言?如果您需要任何进一步的信息,请让我知道 - 这是最好的方式,我可以想出来解释我的情况,这可能是为什么我的谷歌搜索空了。先谢谢您的帮助!

Take notepad for example. You can open a file with notepad (right click and open with, or double clicking on the file if it is already associated with notepad) and it will display the contents of a file. I want to be able to open an xml file with the program that I am writing so that it can do some parsing and give a desired output. What sort of ways are there to do this in java? Do I have to ask for an argument to be passed into the program when it is opened? Would this be easier in C++ or some other language? If you need any further information please let me know -- this was the best way I could come up with to discribe my situation, which may be why my google searches have come up empty. Thank you in advance for your help!

推荐答案

您可以将扩展名与java jar关联,文件名将作为 args [0] 它不会那么简单。我建议你尝试一个你好世界程序。 ;)

You can associate an extension with a java jar and the file name will be passed as args[0] It doesn't get much simpler than that. I suggest you try it with a "hello world" program. ;)

这篇关于如何将文件与Java中的程序相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆