java csv 复杂表头,使用JAVA在CSV文件中合并列

I want to combine columns in csv file using java

here in this file i want combine first two columns "Product No" and "Product Name".

This is My CSV File

Productno,Productname,Price,Quantity

1,java,300,5

2,java2,500,10

3,java3,1100,120

Here is My 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)

{

for (int i = 0; i < 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 this code i get output is below

Product No

Product Name

Price

1

java

300

2

java2

500

3

java3

1100

But I want Output like this....

ProductnoProductname,Price,Quantity

1java,300,5

2java2,500,10

3java3,1100,120

解决方案

while ((row = reader.readNext()) != null)

{

for (int i = 0; i < row.length; i++)

{

// display CSV values

System.out.print(row[i]);

String com = row[i];

out.write(com);

}

System.out.println();

}

this breaks the output only after ove SV line is writen

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值