D
D
Danil2021-02-15 12:36:40
Java
Danil, 2021-02-15 12:36:40

Array of String args[]?

I run the program with command line arguments, the first 3 elements of the args array are the data type, sorting mode, and the output file
is the 4th element of the args array, and then (if any) these are the names of the files (input files) from where you need to take the data
So, I'm trying put in the list of elements, the data of the input files

try {
                BufferedReader reader = new BufferedReader(new FileReader(args[3]));
                while (reader.ready()) {
                    rawData.add(reader.readLine());
                }
            } catch (FileNotFoundException e) {
                System.out.println("Входной файл с таким именем не найден!" + exit);

            } catch (IOException e) {
                System.out.println("Ошибка чтения входных данных");
            }

But after processing this line BufferedReader reader = new BufferedReader(new FileReader(args[h]));
throws an exception FileNotFoundException
The problem is that if I have only one input file, and I assign the 4th element to the inputFileName variable, then everything works
Example of running from the command line java -jar test.jar -a -i out.txt in1.txt in2.txt

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HemulGM, 2021-02-15
@Danicimo

So list what you get after parsing args

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question