想我知道一个文本文件格式,解析的文本文件在Java中的固定格式
说,每行包含4个领域是这样的:
firstword secondword thirdword fourthword firstword2 secondword2 thirdword2 fourthword2 ...
,我需要把它读充分考虑内存
我可以使用这种方法:
open a text file while not EOF read line by line split each line by a space create a new object with four fields extracted from each line add this object to a Set
好,但有更好的东西,一个特殊的3第三方Java库?
,使我们可以预先定义每个文本行的结构,并与一些功能
thirdpartylib.setInputTextFileFormat("format.xml"); thirdpartylib.parse(Set, "pathToFile")
解析文件?
我完全同意Catchwa,你的意思是说更好?你的算法非常清晰,易于阅读/维护。你更期待什么?可扩展性?速度?磁盘访问次数? – 2010-04-26 11:38:28