Read text file in java

后端 未结 5 2066
礼貌的吻别
礼貌的吻别 2020-12-12 00:00

Hey, I need to read a textfile in java. The problem is that the file has the following format:

Id time1 time2 time3 ...
ID2 time1 time2 time3 ...
         


        
5条回答
  •  北海茫月
    2020-12-12 00:27

    One solution is to parse the file once and create an index of the positions of each ids in the file. Then, you can reposition the reading 'cursor' as needed to ids.

    EDIT

    This solution is practical if the whole file content cannot be loaded into memory. To limit the number of physical readings, a LRU cache keeping the most recently read or used id-times combinations could improve performance.

提交回复
热议问题