Java 文件路径问题
我正在尝试完成一个将文件从客户端计算机上传到网络服务器的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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不简单地将传递给 shell 脚本的参数转发给 Java 应用程序呢?我通常会这样做:
这会将执行脚本所用的所有参数传递给java应用程序,您可以对它们进行操作 - 据我所知,您只需要 - 文件路径。我不熟悉 bat 脚本,但我认为它们有一些类似的传递参数的方式。
Why not simply forward the parameters passed to the shell script to the Java application. I usually do something like this:
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.
运行Java程序的批处理文件是什么样的?您确实可以使用这样的参数:
如果您将该行放入文件
runprogram.bat
中,那么您可以使用以下命令运行它:并且
somefilename.xyz
将被传递给作为命令行参数的 Java 程序。What does the batch file look like that runs the Java program? You can indeed use parameters like this:
If you put that line in a file
runprogram.bat
, then you could run it with:and
somefilename.xyz
will be passed to the Java program as a command line argument.不,他们明白了,如果我可以将文件路径作为参数传递给执行的 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....