【问题标题】:Pass the path of an opened file to a batch file [duplicate]将打开文件的路径传递给批处理文件[重复]
【发布时间】:2022-01-20 23:34:52
【问题描述】:

如果我将批处理文件链接为某个文件扩展名的文件关联,那么我可以使用它将参数传递给 Java 程序的主函数。如何获取打开文件的路径作为参数,然后在 Java 中使用它?我想让直接打开我的 Java 程序创建和使用的文件成为可能。

MyFile.extension > 打开方式 > MyBatch.bat

MyBat.bat

java -jar test.jar thisIsWhereThePathBelongs

test.jar 主函数

public static void main(String[] args) {
    System.out.println(args[0]); // thisIsWhereThePathBelongs
}

提前致谢。

【问题讨论】:

  • 这或多或少有效,我可以将参数获取到主函数输出,但是如何将打开文件的路径存储为参数? java -jar test.jar thePath --> thePath 当我打印我的 args 数组的第一个索引时。

标签: java file batch-file file-association


【解决方案1】:

为了让您的批处理(或 .cmd)文件在通过 Open with ... 调用或作为文件扩展名关联时接收到的参数传递,您需要确保将参数 %1 传递给 Java:

MyBat.bat

@echo off
java -jar your.jar your.className %1

【讨论】:

    猜你喜欢
    • 2015-03-22
    • 1970-01-01
    • 2017-08-13
    • 1970-01-01
    • 2018-03-28
    • 2017-12-10
    • 1970-01-01
    • 1970-01-01
    • 2020-04-02
    相关资源
    最近更新 更多