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开发者_StackOverflow中文版 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.
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
...
}
精彩评论