Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 556127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:53:13+00:00 2026-05-13T11:53:13+00:00

I’m working at a small office,I have an application,it’s generate a big text file

  • 0

I’m working at a small office,I have an application,it’s generate a big text file with 14000 lines;

after each generate i must filter it and it’s really boring;

I wanna write an application with java till I’ll can handle it as soon as possible.

Please help me; I wrote an application with scanner (Of course with help 🙂 ) but it’s not good
becase it was very slow;

For example it’s my file :

SET CELL:NAME=CELL:0,CELLID=3;
SET LSCID:NAME=LSC:0,NETITYPE=MDCS,T32=5,EACT=FILTER-NOFILTER-MINR-FILTER-NOFILTER,ENSUP=GV2&NCR,MINCELL=6,MSV=PFR,OVLHR=9500,OTHR=80,BVLH=TRUE,CELLID=3,BTLH=TRUE,MSLH=TRUE,EIHO=DISABLED,ENCHO=ENABLED,NARD=NAP_STLP,AMH=ENABLED(3)-ENABLED(6)-ENABLED(9)

and I want this output (filter 🙂

CELLID :  3
ENSUP  :  GV2&NCR
ENCHO  :  ENABLED
MSLH   :  TRUE
------------------------
Count of CELLID : 2

which solution is the best and the fastest than the other ?

it’s my source code :

public static void main(String[] args) throws FileNotFoundException {
        Scanner scanner = new Scanner(new File("i:\\1\\2.txt"));
        scanner.useDelimiter(";|,");
        Pattern words = Pattern.compile("(CELLID=|ENSUP=|ENCHO=)");

        while (scanner.hasNextLine()) {
          String key = scanner.findInLine(words);

          while (key != null) {
            String value = scanner.next();
            if (key.equals("CELLID=")) 
              System.out.print("CELLID:" + value+"\n");
             //continue with else ifs for other keys
              else if (key.equals("ENSUP="))
            System.out.print("ENSUP:" + value+"\n");

            else if (key.equals("ENCHO="))
            System.out.print("ENCHO:" + value+"\n");
            key = scanner.findInLine(words);
          }
          scanner.nextLine();
        }

}

Thank you very much indeed …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:53:13+00:00Added an answer on May 13, 2026 at 11:53 am

    Since your code has performance issues, you first need to find bottle neck. You can profile it with profiler available with IDE you use.

    However since your code is not high in computation but IO intensive, both in reading file and output using System.out.print, that is where I would suggest you to improve on for improving on file IO.

    .

    Replace this line of code

    Scanner scanner = new Scanner(new File("i:\\1\\2.txt"));
    

    .

    With this lines of code

    File file = new File("i:\\1\\2.txt");
    BufferedReader br = new BufferedReader( new FileReader(file)  );
    Scanner scanner = new Scanner(br);
    

    Let us know if this helps.

    .

    Since previous solution did not helped much, I made few more changes to improve your code. You may have to correct errors in parsing if any. I was able to display output of parsing 392832 lines in approx 5 seconds. Original solution takes more than 50 seconds.

    Chages are as below:

    1. Use of StringTokenizer instead of
      Scanner
    2. Use of BufferedReader for reading file
    3. Use of StringBuilder to buffer output

    .

    public class FileParse {
    
        private static final int FLUSH_LIMIT = 1024 * 1024;
        private static StringBuilder outputBuffer = new StringBuilder(
                FLUSH_LIMIT + 1024);
        private static final long countCellId;
    
        public static void main(String[] args) throws IOException {
            long start = System.currentTimeMillis();
            String fileName = "i:\\1\\2.txt";
            File file = new File(fileName);
            BufferedReader br = new BufferedReader(new FileReader(file));
            String line;
            while ((line = br.readLine()) != null) {
                StringTokenizer st = new StringTokenizer(line, ";|, ");
                while (st.hasMoreTokens()) {
                    String token = st.nextToken();
                    processToken(token);
                }
            }
            flushOutputBuffer();
            System.out.println("----------------------------");
            System.out.println("CELLID Count: " + countCellId);
            long end = System.currentTimeMillis();
            System.out.println("Time: " + (end - start));
        }
    
        private static void processToken(String token) {
            if (token.startsWith("CELLID=")) {
                String value = getTokenValue(token);
                outputBuffer.append("CELLID:").append(value).append("\n");
                countCellId++;
            } else if (token.startsWith("ENSUP=")) {
                String value = getTokenValue(token);
                outputBuffer.append("ENSUP:").append(value).append("\n");
            } else if (token.startsWith("ENCHO=")) {
                String value = getTokenValue(token);
                outputBuffer.append("ENCHO:").append(value).append("\n");
            }
            if (outputBuffer.length() > FLUSH_LIMIT) {
                flushOutputBuffer();
            }
        }
    
        private static String getTokenValue(String token) {
            int start = token.indexOf('=') + 1;
            int end = token.length();
            String value = token.substring(start, end);
            return value;
        }
    
        private static void flushOutputBuffer() {
            System.out.print(outputBuffer);
            outputBuffer = new StringBuilder(FLUSH_LIMIT + 1024);
        }
    
    }
    

    .

    Update on ENSUP and MSLH:

    To me it looks like you have switched ENSUP and MSLH in if statement as below. Hence you see “MSLH” value for “ENSUP” and vice a versa.

    } else if (token.startsWith("MSLH=")) {
        String value = getTokenValue(token);
        outputBuffer.append("ENSUP:").append(value).append("\n");
    } else if (token.startsWith("ENSUP=")) {
        String value = getTokenValue(token);
        outputBuffer.append("MSLH:").append(value).append("\n");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
this is what i have right now Drawing an RSS feed into the php,
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.