I have a method which reads a file and returns the contents of the text file in a list of String array. Find the implementation of the method and how I read it below. Now I want to have the number of lines in the file as well. I can get it as shown below in the comment - Can you please let me know how can I pass the integer variable as well from the method and read the integer as well?
Below - i.e read file should return List consisting of string arrays and an int as well.
public List<String[]> readFile() {
final List<String[]> userList = new ArrayList<String[]>();
BufferedReader bufferedreader = null;
try {
final String FileName="abs.txt"
bufferedreader = new BufferedReader(new FileReader(FileName));
String line = null;
while ((line = bufferedreader.readLine()) != null) {
// Add Variable ++ to get number of lines
final String[] values = line.split(",");
userList.add(values);
}
}
catch (FileNotFoundException ex) {
logError(ex.getMessage());
}
catch (IOException ex) {
logError(ex.getMessage());
}
finally {
try {
if (bufferedreader != null){
bufferedreader.close();
}
}
catch (IOException ex) {
logError(ex.getMessage());
}
}
return userList;
}
This is how I read it:
List<String[]> usersArray1 = new ArrayList<String[]>();
usersArray1=complianceTracker.readFile();