Java 文件路径问题

发布于 2024-09-01 12:38:16 字数 123 浏览 2 评论 0原文

我正在尝试完成一个将文件从客户端计算机上传到网络服务器的java程序。 java程序是用bat脚本执行的。我需要以某种方式将文件名传递给java程序,因为文件名每次都不同。或者我可以以某种方式使用 %1 而不是文件路径吗?我不知道。

I am trying to finish a java program that uploads a file from a client machine to a webserver. The java program is executed with a bat script. I need to pass in a file name to the java program somehow since the filename is different every time. Or can i somehow use %1 instead of the filepath? I dont know.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风轻花落早 2024-09-08 12:38:16

为什么不简单地将传递给 shell 脚本的参数转发给 Java 应用程序呢?我通常会这样做:

#!/bin/zsh

java -jar someapp.jar $@

这会将执行脚本所用的所有参数传递给java应用程序,您可以对它们进行操作 - 据我所知,您只需要 - 文件路径。我不熟悉 bat 脚本,但我认为它们有一些类似的传递参数的方式。

Why not simply forward the parameters passed to the shell script to the Java application. I usually do something like this:

#!/bin/zsh

java -jar someapp.jar $@

This will pass all the arguments with which the script was executed to the java app and you can act upon them - as far as I understand you need only only - the file path. I'm not familiar with bat scripts, but I assume they have some similar way of passing args around.

卷耳 2024-09-08 12:38:16

运行Java程序的批处理文件是什么样的?您确实可以使用这样的参数:

java -jar program.jar %1

如果您将该行放入文件 runprogram.bat 中,那么您可以使用以下命令运行它:

runprogram somefilename.xyz

并且 somefilename.xyz 将被传递给作为命令行参数的 Java 程序。

What does the batch file look like that runs the Java program? You can indeed use parameters like this:

java -jar program.jar %1

If you put that line in a file runprogram.bat, then you could run it with:

runprogram somefilename.xyz

and somefilename.xyz will be passed to the Java program as a command line argument.

雪花飘飘的天空 2024-09-08 12:38:16

不,他们明白了,如果我可以将文件路径作为参数传递给执行的 jar,那就太棒了。只需弄清楚如何将该参数传递给程序中的变量......

No they got it, if i could just pass the filepath as a parameter to the executed jar that would be awesome. Just need to figure out how to pass that parameter into a variable in the program....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文