I am trying to make my code more modular. My question is, once you get the input by calling the getFile method, how can you save it to say an array, etc.?
To be more clear, I want to be able to call the getFileScanner method and it return whatever is on the file the user enters. Then within the main method, I want to be able to set that input (whatever was on the .txt file) to an array(to be written). How can I go about saving the input in the main method? On another post separate from this one, a user suggested I make my code more modular and suggested some of the below code. I am just trying to understand what the user had intended and split some of the code up.
import java.io.File ;
import java.io.FileNotFoundException ;
import java.util.Scanner ;
public class scanTest {
public static void main(String[] args) throws FileNotFoundException {
System.out.println("Please enter the file");
System.out.println(getFileScanner());
}
public static Scanner getFileScanner() throws FileNotFoundException {
Scanner user_input = new Scanner(System.in);
String filepath = user_input.next();
System.out.println("Filepath read: " + filepath);
// Read input file
Scanner input = new Scanner(new File(filepath));
System.out.println(input);
return input;
}
}