使用我的可执行jar文件进行文件关联 [英] File association using my executable jar file

查看:88
本文介绍了使用我的可执行jar文件进行文件关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的文件指定了扩展名* .XSCA.当用户使用我的可执行jar文件打开它时,我想读取该文件的内容.我该怎么办?

I have assigned an extension name for my files called *.XSCA. I would like to read the content of this file when the user click on it using my executable jar file to open it. How can I do that?

推荐答案

假设您在Windows下工作:

assuming you work under windows:

  • 创建一个调用您的jar的批处理文件(* .bat)(应该类似于"java -jar yourJar.jar")
  • 右键单击您类型的文件,转到属性",然后将打开文件的程序更改为该批处理文件
  • 让批处理文件将文件位置作为参数传递给您的jar

您可以使用任何文本编辑器编写批处理文件.使用谷歌找出如何.它将只是您的jar的包装,您可以在Windows中将其与文件扩展名类型相关联.

You can write a batch-file with any text-editor. Use google to find out how. It will just be a wrapper for your jar that you can associate in windows with your file-extension-type.

好的,一步一步来

那是您的Java程序(将它作为可运行的jar与Eclipse一起导出):

That's your Java program (export it with Eclipse as a runnable jar):

public class ExtensionOpener {

    public static void main(String[] args) throws InterruptedException {

        System.out.println("args:");

        for(String arg: args) 
            System.out.println(arg);

        Thread.sleep(3000);
    }
}

这是批处理文件(只需将其另存为例如 your-starter.bat ):

That's the batch-file (just save it as e.g. your-starter.bat):

@echo run bat
java -jar C:\Users\Thomas\Desktop\FileOpener.jar -file -%1

现在,在文件( your.fileextension )上单击鼠标右键,然后转到属性并将其与批处理文件关联.就是这样.

Now click right on your file (your.fileextension) and go to properties and associate it with the batch-file. That's it.

这篇关于使用我的可执行jar文件进行文件关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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