简体   繁体   中英

Parse Huge Text String String.split() (Or) Regular Expression (Or) Any other Way?

I'm having a text file which has 3,00,000 lines where the line delimiter is '

example,

    UNB+UNOA:1+KRR+KRR+050313:1257+1+++++KRR'
    UNH+1+BAPLIE:D:95B:UN:SMDG20'
    BGM++1+9'
    ......
    ......
    .......

I want to read the text line by line.

Huge users import similar kind of files to the system.

What is the best way to read the file line by line by delimeting the text?

Can we parse the whole text via regular expression in java? if yes, how to do it?

String.split() might be slower if we have a powerful regular expression to parse the text.

Please help me with your suggestion to achieve the best performance.

Thanks.

if you want to read lines from a text file just do this...

     BufferedReader br = new BufferedReader(new FileReader("YourPath"));
     String line = br.readLine();
     while (line != null) {
            //Do Something...
         line = br.readLine();
     }
     br.close();

for example if your text file is :

I

Am

HAPPY

the output is

I

Am

Happy

the same..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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