请随意跳到TL;Dr.
这就是我通常使用.jar的经验,在命令中:
java -cp test.jar test q a o
打开罐子
接下来,像
UF UD UR etc, enter to the program
这可能会给我20行“回复”
我想做以下工作:
1-使用上述参数运行jar
这些参数应该由gui来确定(复选框等,我可以确定)。
2-当.jar打开时,按照
你等等,和以前一样。
这些提交也应该由gui决定。
3-从后台的.jar中获取输出,并将其放入一个标签或其他东西中(一旦它是字符串,我就可以开始了)。我只需要帮忙抓它)。
基本上:
打开罐子
在罐子里输入东西
获取输入后的输出
显示输出。
我看到了一些与I/O相关的链接,并试图阅读它们,但大多数都是关于这个主题的问题,但没有有效的答案。
TL;博士
如果有人能将我链接到一个运行在命令中的.jar Java I/O工作示例,我将非常感激。

最佳答案

您可以尝试直接玩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
  ...
}

09-05 15:06
查看更多