i have write a code for making a string that is being read from CSV file.
i want to make a string from particular location of each and every line.
i have attached a code what i have done.but i want it as it for any number of location.
In dataset.csv file there is rows like
abc,12,male,12345,flu,yes
apm,15,female,32165,fever,no
plz,45,female,32154,flu,no
ert,32,female,32564,fever,yes
If i run following code with identifier =3 and location are 1,2,3 then i need output as
12,male,12345 in first iteration
15,female,32165 in second iteration
and so on.
public static void main(String args[])throws IOException
{
int q,i,loc[];
DataInputStream din = new DataInputStream(System.in);
System.out.println("Enter No. of Idenifier =");
q=Integer.parseInt(din.readLine());
loc= new int[q];
for(i=0;i<q;i++)
{
System.out.println("Enter "+i+"th identifier location :");
loc[i]=Integer.parseInt(din.readLine());
}
BufferedReader CSVFile = new BufferedReader(new FileReader("dataset.csv"));
String dataRow = CSVFile.readLine(); // Read first line.
int dataIndex = 0;
while (dataRow != null)
{
String[] dataArray = dataRow.split(",");
for (String item:dataArray) {
if(item.length()==0)
System.out.print("no records found..." + "\t");
else{ continue;}
}
String aspStr = null;
for(int j=0;j<q;j++)
{
aspStr += dataArray[loc[j]]+",";//+dataArray[loc[1]]+","+dataArray[loc[2]];
}
dataRow = CSVFile.readLine();// Read next line of data.
}
but i got null at the starting of each aspStr output
So please tell me how can i got output as
12,male,12345
15,female,32165
and so on.
please reply.