想我知道一個文本文件格式,解析的文本文件在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