I have to sort a buch of integers from a text file. Is it possible to pass the numbers from the file as (String[] args) to my main method?
Cheers
next to the Run button (the green arrow) there's a downwards arrow for selecting the run configuration.
click it, go to run configuration. there you can add a new setup for a java program, and in the tabs you can find "Arguments"
EDIT: to read the text file:
put the path inside the run configuration arguments
now in the public static void main(String[] args) you will want to read the text file. you can read the first line, and then use args = line.split(" ")
this will override the String[] args array. remember to remove this if you export to jar, unless you will use the file path as the argument
the code for reading the file is something like this:
Scanner sc = new Scanner(new File(args[0]));
args = sc.nextLine().split(" ");