java - 从以“|”分隔的 txt 文件中获取特定值
问题描述
如何从以“|”分隔的 txt 文件中获取特定值 . 我试图从第 18 列中获取值,然后我得到了,但我没有得到所有这些值。如果我取出验证 if(csvRecord.size() >= csvParser.getRecordNumber())
,我会得到错误索引 18 超出长度 1 的范围。
有人已经使用过 csvParser 并且可以帮助我吗?
这是我的代码:
public static List<String> murexMHEU_TradeCash() throws Exception {
List<String> MHEUList = new ArrayList<String>();
String path = Setup.MHEU_TradeCash;
try (
BufferedReader br = new BufferedReader(new FileReader(path));
CSVParser csvParser = new CSVParser(br, CSVFormat.DEFAULT.withDelimiter('|'));
) {
//Skip first line
br.readLine();
for (CSVRecord csvRecord : csvParser) {
if(csvRecord.size() >= csvParser.getRecordNumber()){
// Accessing Values by Column Index
String MurexCounterpartyRef = csvRecord.get(18);
MHEUList.add(MurexCounterpartyRef);
}
}
}
catch(IOException e) {
System.out.println("File not found - " + e.getMessage());
}
return MHEUList;
}
解决方案
推荐阅读
- android-room - RoomDB 是否支持 dropAllTables() 和 createAllTables()?
- python - 确定 pandas Dataframe 中的列是否包含 DATE 或 DATETIME 信息的最简单方法
- lua - 在 Lua 中使用“\”操作 sting 时出错
- android - Android模拟器确实出现了,但它只显示黑屏
- javascript - 将带有 EventEmitter 的消息发送到 observable 并从 observable 订阅发送消息 EventEmitter next,而不是销毁
- python - altair pandas 值计数水平条形图
- python - 如何使用 python 64 位读取 .mdb 文件?
- angular - 如何传递 id 来获取 api url?(Angular)
- javascript - 从数组中提取对象 - 打字稿
- excel - 将数据从多个工作表中获取到为另一个工作表定义的变量中