[HTML]
import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.StringTokenizer;
public class readCSV {
public static void main(String args[]) {
try{
File file = new File("c:/java/Number of Requests per Device.csv");
BufferedReader bufRdr = new BufferedReader(new FileReader(file));
String line = null;
int monthNumber = 0;
int deviceName = 0;
int activeUsers = 0;
String vals[][][] = new String[100][100][100];
//read each line of text file
while((line = bufRdr.readLine()) != null)
{
StringTokenizer st = new StringTokenizer(line,",");
while (st.hasMoreTokens())
{
//get next token and store it in the array
vals[monthNumber][deviceName][activeUsers] = st.nextToken();
System.out.println(vals[monthNumber][deviceName][activeUsers]);
}
/*
deviceName=0;
activeUsers=0;
monthNumber++;
System.out.println(vals[monthNumber][0][0]);
*/
}
//System.out.println(vals[monthNumber][0][0]);
}catch(Exception e){
System.out.println("Exception Fired is:" + e);
}
}
}
[/HTML]
CSV file sample is as follows:
Month 1,blackberry8700,6397.0
Month 1,blackberry7730,1456.0
Month 1,blackberry7290,1113.0
Month 1,blackberry7100,727.0
Month 2,blackberry8700,1327.0
Month 2,blackberry7730,316.0
Month 2,blackberry7290,16.0
Month 2,blackberry7100,27.0
How do i iterate through all this elements and store in and array or some suitable data structure like unique month numbers in [months], device names in [device name] and active users in [active users] and retreive it back and store it in a following fashion:
Month 1,2
blackberry8700,6397.0,1327.0
blackberry7730,1456.0,316.0
blackberry7290,1113.0,16.0
blackberry7100,727.0,27.0
can some one help its urgent and im stuck!!