java - 如何知道我在 CSVReader 中有文件的最后一行
问题描述
我使用 java 中的 CSVReader 将那些大文件导入数据库中。
如果我想知道我有文件的最后一行然后文件结束,我应该使用什么方法?
我的代码是:
String pathFile = "D:\\";
String ifrsFileName = "test.csv";
int countToInput = 1000;
CSVReader ifrsReader = new CSVReader(new FileReader(pathFile + ifrsFileName));
String[] nextLine;
long counter = 0;
while ((nextLine = ifrsReader.readNext()) != null) {
deposit = process.getEntityObject(nextLine);
deposits.add(deposit);
if (counter == countToInput - 1 ) {
repository.insertToDB(deposits, connection, pstmt);
counter = 0;
deposits.clear();
}
counter++;
}
我的问题是最后读取 1000 条记录后,我的程序结束,如果剩下的记录少于 1000 条,它们将不会被导入。多谢
解决方案
推荐阅读
- r - 为什么这个关于矩阵乘法的代码与 outer() 命令错误
- arrays - 数组不显示正确的值
- javascript - 如何在 Node 中使用 date-fns 库处理 UTC 数学?
- ffmpeg - ffmpeg vaapi - 缩放视频,保持纵横比并用黑线填充
- time-complexity - 为什么归并排序的时间复杂度没有 O(2^log(n)) 类似于斐波那契数列生成的树?
- sql - popSQL 上公共架构的权限被拒绝
- winapi - 等待定时器是多媒体定时器吗?
- ssh - xorq 在寄存器中做了什么?
- python - Python Selenium:使用 webdriver 定位并单击 -> Tooltip 可见,没有“id”或“name”
- angular - 将@angular/fire 从 6.x 升级到 7.x