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 8672143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:07:42+00:00 2026-06-12T19:07:42+00:00

I need to process a large text file (600 MB approximately) in order to

  • 0

I need to process a large text file (600 MB approximately) in order to format it correctly, writing the formatted output to a new text file. The problem is that writing the content into the new file stops at about 6.2 MB. Here is the code:

/* Analysis of the text in fileName to see if the lines are in the correct format 
     * (Theme\tDate\tTitle\tDescription). If there are lines that are in the incorrect format,
     * the method corrects them.
     */
    public static void cleanTextFile(String fileName, String destFile) throws IOException {
        OutputStreamWriter writer = null;
        BufferedReader reader = null;

        try {
            writer = new OutputStreamWriter(new FileOutputStream(destFile), "UTF8");
        } catch (IOException e) {
            System.out.println("Could not open or create the file " + destFile);
        }

        try {
            reader = new BufferedReader(new FileReader(fileName));
        } catch (FileNotFoundException e) {
            System.out.println("The file " + fileName + " doesn't exist in the folder.");
        }

        String line;
        String[] splitLine;
        StringBuilder stringBuilder = new StringBuilder("");

        while ((line = reader.readLine()) != null) {
            splitLine = line.split("\t");
            stringBuilder.append(line);

            /* If the String array resulting of the split operation doesn't have size 4,
             * then it means that there are elements of the news item missing in the line
             */
            while (splitLine.length != 4) {
                line = reader.readLine();
                stringBuilder.append(line);

                splitLine = stringBuilder.toString().split("\t");
            }
            stringBuilder.append("\n");
            writer.write(stringBuilder.toString());
            stringBuilder = new StringBuilder("");

            writer.flush();
        }

        writer.close();
        reader.close();

    }

I’ve already looked for answers, but the problem is usually related to the fact that the writer is not being closed or the absence of the flush() method. Therefore, I’m thinking that the problem is in the BufferedReader. What am I missing?

  • 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-06-12T19:07:43+00:00Added an answer on June 12, 2026 at 7:07 pm

    Look at this loop:

    while (splitLine.length != 4) {
        line = reader.readLine();
        stringBuilder.append(line);
    
        splitLine = stringBuilder.toString().split("\t");
    }
    

    If you ever end up with more than 5 items in splitLine, you’ll just keep reading data forever… you won’t even notice when you’ve reached the end of the file, as you’ll just keep appending null to the StringBuilder. I don’t know whether this is what’s happening (we don’t know what your data looks like) but it’s certainly feasible, and you should guard against it.

    (You should also use a try/finally block for closing resources, but that’s a separate matter.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large text file I want to process in Clojure. I need
I need to implement a process, wherein a text file of roughly 50/150kb is
I often need to process large text files containing headers in the first line.
I need to process a large file, around 400K lines and 200 M. But
I need to process a large number of files in a directory. The files
I need to process a large C++ codebase, renaming pretty much everything (classes, parameters,
I need to process the incoming predefined ASN format data(coming from verity of clients
I need to process DICOM formatted medical images and visualize them in 3D, also
I have the next problem: I need to process only 1 request at a
I have a program to process very large files. Now I need to show

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.