简体   繁体   English

读取.txt文件并更新Java Bean对象

[英]Reading a .txt File and updating Java Bean Objects

I have the following file in .txt format 我有以下.txt格式的文件


*XXX=017
*tag=016
*foci
String value
*XXX=018
*tag=024
*foci
*listname   
*XXX=018
*tag=024
*foci
String value
String value
String value

Here as we can see we have some predefined tags, and for each tag some value is associated with it. 如我们所见,这里有一些预定义的标签,并且对于每个标签,都有一些与之关联的值。

Now each *XXX marks the beginning for an object to be updated. 现在,每个*XXX标志着要更新的对象的开始。 The object will store the values like 018, 024, String value associated with *foci or list value. 该对象将存储诸如018、024,与* foci关联的字符串值或列表值之类的值。 Then again it will move to next *XXX . 然后它将再次移动到下一个*XXX

I have created bean objects and also reading the file. 我已经创建了bean对象,还读取了文件。 But as there are no specification on how many lines will be available after the *foci tag, it is difficult to group the objects correctly. 但是,由于没有关于* foci标记后可以使用多少行的规范,因此很难正确地对对象进行分组。 Can any one give any suggestion that how to differentiate each object or How to determine that we have reached end of *foci tag data or end of *XXX tag data. 谁能提出任何关于如何区分每个对象的建议,或者如何确定我们是否已到达*foci标签数据的末尾或*XXX标签数据的末尾的任何建议。

Thanks 谢谢

You could use Java Properties instead of reading from the .txt files. 您可以使用Java属性而不是从.txt文件中读取。

1.*XXX=017
1.*tag=016
1.*foci
2.*XXX=018
2.*tag=024
2.*foci *listname 

numbers can be used to group the set of inputs together and can be appended into the key value while fetching the property from the properties. 数字可用于将一组输入分组在一起,并可在从属性中获取属性时将其附加到键值中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM