Usually I would suggest using a FileReader, but you said that you are refactoring code which reads this information from the user. I guess, you are reading the input with a Scanner, so the easiest way to change this is by replacing
Scanner sc = new Scanner(System.in);
with this:
Scanner sc = new Scanner(new File("someFile.txt"));
You can then use the Scanner like that:
String fileName = "cars.txt";
List<Car> cars = new ArrayList<>();
try (Scanner sc = new Scanner(new File("someFile.txt"))){
int count = sc.nextInt();
for (int i = 0; i < count; i++) {
int year = sc.nextInt();
String brand = sc.next();
String type = sc.next();
cars.add(new Car(year, brand, type));
}
} catch (IOException e) {
System.err.println("error reading cars from file "+fileName);
e.printStackTrace();
}
Also use sc.hasNext() and sc.hasNextInt() before you read from the Scanner, since your code might otherwise throw exceptions if the file doesn't have valid content..
You can see the Car class in another (distinct) answer I posted