I have been testing with my own file and it seems to work correctly, so I do not get why it is still failing the 3rd condition.
Read a file name from the console.
Search the file for information related to the specified id. Display it in the format used in the file.
The program is started with one argument: id (an int). Close the streams.
The file data is separated by spaces and stored in the following order: id productName price quantity
where id is an int
productName is a String — it can contain spaces
price is a double
quantity is an int
The information for each product is stored on a separate line.
Requirements:
The program should read a file name from the console.
Create an input stream for the file.
The program should search the file and display information related to the specified id passed as the first argument.
The problem is going to occur because of this "productName is a String — it can contain spaces". The code above splits each line and space, which means that when the product name is more than one word all the values for that specific line will be spread out more than 4 indices in the array.