0

I am working on a java swing application which currently allows a user to import one or more files to be processed.

This is done right now by executing the jar using

java -jar [jarname] [filename 1] [filename 2] ... [filename N].

I am tasked with to change the behaviour so as to keep it working in this current mode and add another mode of execution by adding an option parameter:

java -jar [jarname] [filename 1] -o [option].

In the second mode, I need to make sure that the arguments contain a single filename argument with a single option flag followed by a single option argument. The option will be used to process the file. Alternatively, if the jar is executed in the first mode using only one file, there is a menu option in the application that the user should be able to use to process the file with the required option.

I am looking for ideas/tips to accomplish this.

Thanks in advance.

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
  • Have you tried anything yet? What exactly is giving you trouble? – VGR Nov 04 '15 at 17:28
  • How are you reading the arguments? Using `public void main(String[] args)` and using args as in the input? Just check to see if `-o` appears in args, and treat the value after that as the option to set – phflack Nov 04 '15 at 17:35
  • Hint: what happens if you have a file named `-o`? – Raedwald Nov 04 '15 at 20:43
  • This is my argument parsing logic so far – torukmaktoh Nov 04 '15 at 21:56
  • `if (args.length > 0) { if (args.length == 3) { // check if the second argument is the filter option "-o" if (args[1].compareTo("-o") == 0) { String option = args[2].toLowerCase(); String[] fileName = new String[1]; fileName[0] = args[0]; mode2(fileName); mode2.option(option); } else { mode1(); } } else { mode1(); } } ` – torukmaktoh Nov 04 '15 at 22:01

0 Answers0