signature=1be7575a614ba3597c2c53247a739d1c,excel - Invalid header signature; read 0x54535543092E4F4E...

So guys i finally found the best solutions i guess to read and import data from my Tab-separated file using openCSV library, and it goes well for all types of CSV file (Character separated value) with titles, we have just to change the separator. Here is the code:

File xlsFile = new File(path);

CSVReader reader = new CSVReader(new FileReader(xlsFile), '\t');

ArrayList data = new ArrayList();

String[] nextLine;

while ((nextLine = reader.readNext()) != null) {

final int size = nextLine.length;

//handle empty lines

if (size == 0) {

continue;

}

String debut = nextLine[0].trim();

if (debut.length() == 0 && size == 1) {

continue;

}

data.add(nextLine);

}

String[] titles = data.get(0);

data.remove(0);

ArrayList> mappedData = new

ArrayList>(data.size());

final int titlesLength = titles.length;

for (String[] oneData : data) {

final Map map = new HashMap

for (int i = 0; i < titlesLength; i++) {

final String key = titles[i];

final String value = oneData[i];

map.put(key, value);

}

mappedData.add(map);

}

And then we have to get values from the mappedData by their keys(titles or columns name in my case)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值