I have wrote the following for scanning few lines of code as a string and parsing it to an integer. But within my main method, I am using p.letsReadIn to read in the file. Does anyone know how I can convert this to use command line argument instead for taking in the file? So instead of having the user change p.letsReadIn("ReadMuah.txt"); every time, they can just use command line just for reading in the file.
public void letsReadIn(String filename) throws FileNotFoundException {
int x;
Scanner scan = new Scanner(new File(filename));
StringTokenizer st;
String nextLine = scan.nextLine();
st = new StringTokenizer(nextLine);
x = Integer.parseInt(st.nextToken());
nextLine = scan.nextLine();
st = new StringTokenizer(nextLine);
y= Integer.parseInt(st.nextToken());
nextLine = scan.nextLine();
st = new StringTokenizer(nextLine);
z= Integer.parseInt(st.nextToken());
for (int i = 0; i < x; i++) {
nextLine = scan.nextLine();
st = new StringTokenizer(nextLine);
listing.add(Integer.parseInt(st.nextToken()));
}
scan.close();
}
public static void main(String[] args) throws FileNotFoundException {
BagItems p = new BagItems();
p.letsReadIn("ReadMuah.txt");
p.StartBagging();
}