Bharath Kumar Reddy
Bharath Kumar Reddy

Reputation: 53

Including commas when writing to csv file in java, with different string each time

I'm writing a program where I need to write data to csv. However the string what I'm writing to csv has some commas. So when I'm writing to it I'm getting values in different fields, which I don't want Eg: my string will come like : 165328,1234582,21346 I'm getting output as each value in one field, but I want the string as it is in one field

        while((s=lnr.readLine())!=null)
        {
                     str=s.split(" ");
                     br.write(str[7]);
        }

Please add the required thing to get the desired output. Eg : the string I'm writing will look like this 165328,123482,123414...

Upvotes: 0

Views: 4878

Answers (1)

Priyambada Madala
Priyambada Madala

Reputation: 186

Write the string which contains comma in double quotes and then write it into the csv file with File Writer or any writer you wish .

 value="\"" +value + "\"";
 fos.append(value);

Upvotes: 4

Related Questions