为Java/Groovy导入文本文件处理库?

时间:2023-01-28 09:15:48

In a lot of real life implementations of applications we face the requirement to import some kind of (text) files. Usually we would implement some (hardcoded?) logic to validate the file (eg. proper header, proper number of delimiters, proper date/time value,etc.). Eventually also need to check for the existence of related data in a table (eg. value of field 1 in text file must have an entry in some basic data table).

在许多应用程序的实际实现中,我们都需要导入某种(文本)文件。通常我们会实现一些(硬编码?)逻辑来验证文件(例如。正确的标题、正确的分隔符数量、正确的日期/时间值等)。最后还需要检查表中是否存在相关数据(如。文本文件中的字段1的值必须在某些基本数据表中有一个条目)。

While XML solves this (to some extend) with XSD and DTD, we end up hacking this again and again for proprietary text file formats.

虽然XML使用XSD和DTD解决了这个问题(在某种程度上进行了扩展),但我们最终还是会对私有文本文件格式进行一次又一次的黑客攻击。

Is there any library or framework that allows the creation of templates similar to the xsd approach ? This would make it way more flexible to react on file format changes or implement new formats.

是否有任何库或框架允许创建与xsd方法类似的模板?这将使响应文件格式更改或实现新格式变得更加灵活。

Thanks for any hints

感谢任何提示

Sven

斯文

1 个解决方案

#1


1  

Closest thing I can think of is FileHelpers. It's in C#, so it would have to be ported to Java, but that shouldn't be a big deal.

我能想到的最接近的东西是文件助手。它在c#中,所以必须将它移植到Java中,但这不是什么大问题。

#1


1  

Closest thing I can think of is FileHelpers. It's in C#, so it would have to be ported to Java, but that shouldn't be a big deal.

我能想到的最接近的东西是文件助手。它在c#中,所以必须将它移植到Java中,但这不是什么大问题。