0

I was wondering how I would take additional input into a java program from the very line that I call the program to run from?

The input needs to be something like this:

java program abc.fsm <qwerty.txt

where I could run my program "program" then save the two bits of text "abc.fsm" and "qwerty.txt" as strings then use them to later to call upon files and parse them

  • 2
    What have you tried so far? – johnny243 Sep 30 '19 at 17:36
  • 1
    In `public static void main(String [] args)` the `args` are all of the command line arguments the program was run with as a `String` array. – Nexevis Sep 30 '19 at 17:37
  • I tried using the java util.scanner, but my teacher said this is not the approach i should take when i asked him, other than that, i got nothing –  Sep 30 '19 at 17:37
  • 1
    @LiamKr You really don't have to anything except use `args` directly. AKA `String str = args[0]`, `str` will now hold `abc.fsm`. – Nexevis Sep 30 '19 at 17:39
  • @Nexevis i completely forgot about that! This is the first coding i have done since may. Thank you very much! –  Sep 30 '19 at 17:39
  • 2
    Possible duplicate of [Java Command line arguments](https://stackoverflow.com/questions/716153/java-command-line-arguments) – Nexevis Sep 30 '19 at 17:40
  • @Nexevis And then for String str1 = args[1] , str1 would hold –  Sep 30 '19 at 17:45

0 Answers0