b把csv文件,用java读取成java bean,文件格式:# 招商银行交易记录 # 导出时间: [ 2023-01-16 15:19:00] # 账 号: [一卡通:6214********5778 招商银行] # 币 种: [ 人民币] # 起始日期: [20220116] 终止日期: [20230116] # 过滤设置: 无 交易日期,交易时间,收入,支出,余额,交易类型,交易备注 " 20230116"," 12:13:22","","59.90","15180.81"," 网联协议支付"," 支付宝 - 赵靖元" " 20230116"," 12:05:21","0.07","","15240.71"," 网联付款交易"," 拼多多支付 - 乔彬 -" " 20230116"," 11:02:35","","36.88","15240.64"," 银联快捷支付"," 美团 - 美团支付 - 美团支付" " 20230116"," 10:35:58","0.02","","15277.52"," 网联付款交易"," 拼多多支付 - 乔彬 -" " 20230116"," 09:21:09","69.00","","15277.50"," 银联快捷支付"," 支付宝 - 支付宝 - 消费" " 20230115"," 19:12:54","52.00","","15208.50"," 网联退款"," 支付宝 - 中国铁路网络有限公司"
时间: 2023-02-26 07:53:16 浏览: 397
java 读取和写入csv文件 (自动提取和转换成对象数据)-附件资源
Java支持读取CSV文件并将其转换为Java Bean对象。这通常可以通过使用第三方库(如OpenCSV)来实现。
首先,需要创建一个Java Bean类,它映射到CSV文件中的每一行数据。然后,可以使用OpenCSV库的API读取CSV文件,将其转换为Java Bean对象的列表。
代码示例:
```
import java.io.FileReader;
import java.util.List;
import com.opencsv.bean.CsvToBeanBuilder;
public class CSVReader {
public static void main(String[] args) throws Exception {
FileReader fileReader = new FileReader("file.csv");
List<YourJavaBeanClass> beans = new CsvToBeanBuilder(fileReader)
.withType(YourJavaBeanClass.class)
.build()
.parse();
for (YourJavaBeanClass bean : beans) {
System.out.println(bean);
}
}
}
```
这是一个使用OpenCSV读取CSV文件并将其转换为Java Bean的简单示例。
阅读全文