Java 中 .jar 的输入/输出帮助?

发布于 2024-11-19 02:26:37 字数 561 浏览 1 评论 0原文

请随意跳到 tl;dr。

这就是我对 .jar 的通常体验,在命令中:

java -cp test.jar test qa o 打开罐子

接下来,类似 UF UD UR 等,进入程序

这给了我大约 20 行“响应”,

我想要执行以下操作:

1 - 使用上面的参数运行 jar 这些参数应该由 GUI 确定(复选框等,我肯定可以做到这一点。)

2 - 当 .jar 打开时,提交一些类似于 UF UD UR 等等,就像以前一样。 这些提交也应由 GUI 确定。

3 - 在后台获取 .jar 的输出并将其放入标签或其他东西中(一旦它位于字符串中,我就可以开始了。我只需要帮助抓取它)。

基本上: 打开罐子 在jar中输入东西 获取输入后的输出 显示输出。

我看到了一些与 I/O 相关的链接,并尝试阅读它们,但大多数都是有关该主题的问题,但没有有效的答案。

太长了;博士 如果有人可以将我链接到带有在命令中运行的 .jar 的 java I/O 的工作示例,我将非常感激。

Feel free to jump to the tl;dr.

This is how my usual experience with my .jar is, in command:

java -cp test.jar test q a o
to open the jar

Next, something like
UF UD UR etc, enter to the program

This gives me maybe 20 lines of 'response'

I want to do the following:

1 - run the jar using paramaters like above
These parameters should be determined by the GUI (checkboxes, etc, I can do this surely.)

2 - while that .jar is open, submit something along the lines of
UF UD UR etc, just like before.
These submissions should be determined by the GUI as well.

3 - take the output from that .jar in the background and throw it into a label or something (once it's in a String, I'm good to go. I just need help grabbing it).

Basically:
open jar
input stuff in jar
get output that comes after input
display output.

I've seen a few links related to I/O and I've tried to read up on them, but most of them are questions about this subject, but no working answers.

tl;dr
If someone could please link me to a working example of java I/O with a .jar that runs in command, I would appreciate this immensely.

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

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

发布评论

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

评论(1

夏见 2024-11-26 02:26:37

您可以尝试直接使用 java.util.JarFile 进行操作:

JarFile jar = new JarFile( "path to jar" ); // Opens the jar

Enumerator<JarEntry> es = jar.entries(); //Enumerator to the jar entries

while( es.hasMoreElements() ) { //Iterates until all entries have been visited

  JarEntry entry = es.nextElement(); //Gets the next entry in the jar

  System.out.println(  entry.getName() ); //Prints the entry name

  InputStream in = jar.getInputStream( entry ); //returns an inputstream from the entry
  ... 
}

You can try playing directly with java.util.JarFile:

JarFile jar = new JarFile( "path to jar" ); // Opens the jar

Enumerator<JarEntry> es = jar.entries(); //Enumerator to the jar entries

while( es.hasMoreElements() ) { //Iterates until all entries have been visited

  JarEntry entry = es.nextElement(); //Gets the next entry in the jar

  System.out.println(  entry.getName() ); //Prints the entry name

  InputStream in = jar.getInputStream( entry ); //returns an inputstream from the entry
  ... 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文