For example, I have two CSV files in folder and need to read data from one file line by line, and store it in array list A like file 2 to array list B dynamically.. i.e. if there is 3 file it should store in array list C
public class DashboardReport
{
public static void main(String[] args)
{
int count = 0;
String line = "";
File folder = new File("D:/April");
File[] listOfFiles = folder.listFiles();
System.out.println("Count" + listOfFiles.length);
count = listOfFiles.length;
List books = new ArrayList();
for (int i = 0; i <= listOfFiles.length; i++)
{
if (listOfFiles[i].isFile())
{
System.out.println("File " + listOfFiles[i].getName());
Path pathToFile = Paths.get(listOfFiles[i].getName());
try (BufferedReader br = Files.newBufferedReader(
pathToFile, StandardCharsets.US_ASCII))
{
line = br.readLine();
String[] attributes = {};
while (line != null)
{
attributes = line.split(",");
books.add(attributes);
line = br.readLine();
}
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
else if (listOfFiles[i].isDirectory())
{
System.out.println("Directory " + listOfFiles[i].getName());
}
}
}
}