data1,true,2000,422
data2,false,2001,421
data3,true,2050,427
data4,true,2004,432
the above data is in sample.txt. I want to write a program using a for loop and any filereader class or by any means, such that my output will be stored in as follows:

My_Data[1]= data1,true,2000,422
My_Data[1][0]= data1
My_Data[1][1]= true
My_Data[1][2]= 2000

My_Data[2]= data2,false,2001,421
My_Data[2][0]= data2
My_Data[2][1]= false
I want to access each My_Data[i] individually and under that My_Data[i][0] ,My_Data[i][1] and so on .

Can anyone please help writing this type of code ?

Well you need help and I'm happy.

Here are some steps:

  1. Create a ArrayList<String[]> to hold split strings.
  2. Use BufferedReader to read the content of file line by line ( BufferedReader#readLine() method)
  3. Use String#split() method to split the string and add an array into arrayList object

Please include code what you've tried so far while posting answer of my post here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.