I have been working with buffering a file on my local drive to parse and obtain certain data. For test purposes I was easily able to do it this way:
public static void main(String[] args) {
fileReader fr = new fileReader();
getList lists = new getList();
File CP_file = new File("C:/Users/XYZ/workspace/Customer_Product_info.txt");
int count = fr.fileSizeInLines(CP_file);
System.out.println("Total number of lines in the file are: "+count);
List<String> lines = fr.strReader(CP_file);
....
}
}
fileReader.java file has the following function:
public List<String> strReader (File in)
{
List<String> totLines = new ArrayList<String>();
try
{
BufferedReader br = new BufferedReader(new FileReader(in));
String line;
while ((line = br.readLine()) != null)
{
totLines.add(line);
}
br.close();
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//String result = null;
return totLines;
}
Now I want the file path to be passed as a Command line Argument instead. I tried a few things but I am kind of new to this and wasnt able to make it work. Can someone please help and explain what all changes I need to make in order to incorporate that change in my code.