Combine Columns in CSV file using JAVA -
i want combine columns in csv file using java here in file want combine first 2 columns "product no" , "product name".
this csv file
productno,productname,price,quantity 1,java,300,5 2,java2,500,10 3,java3,1100,120
here code
private void parseusingopencsv(string filename) { csvreader reader; filewriter out = null; csvwriter outt; try { reader = new csvreader(new filereader(filename)); string[] row; try { out= new filewriter("e:/data/test/newww.csv"); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } try { while ((row = reader.readnext()) != null) { (int = 0; < row.length; i++) { // display csv values system.out.println(row[i]); string com = row[i]; out.write(com); } } } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } catch (filenotfoundexception e) { system.err.println(e.getmessage()); }finally{ if (out != null) { try { out.close(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } } }
by using code output below
product no product name price 1 java 300 2 java2 500 3 java3 1100
but want output this....
productnoproductname,price,quantity 1java,300,5 2java2,500,10 3java3,1100,120
while ((row = reader.readnext()) != null) { (int = 0; < row.length; i++) { // display csv values system.out.print(row[i]); string com = row[i]; out.write(com); } system.out.println(); }
this breaks output after ove sv line writen
Comments
Post a Comment