string tokenizer in Java

后端 未结 7 1305
耶瑟儿~
耶瑟儿~ 2020-12-02 20:58

I have a text file which contains data seperated by \'|\'. I need to get each field(seperated by \'|\') and process it. The text file can be shown as below :

7条回答
  •  死守一世寂寞
    2020-12-02 21:43

    StringTokenizer ignores empty elements. Consider using String.split, which is also available in 1.4.

    From the javadocs:

    StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead.

提交回复
热议问题