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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:39:38+00:00 2026-06-05T05:39:38+00:00

How would I read two log files which are one TB in size without

  • 0

How would I read two log files which are one TB in size without running out of the memory on my machine.I would be doing some comparison on both of them .I would like to do this in Java.Would the below code work?My concern is that the FileStream would not be able to hold the data of the log file.

public static void main(String args[])
{
  try{
     // Open the file that is the first 
     // command line parameter
     FileInputStream fstream = new FileInputStream("textfile.txt");
     // Get the object of DataInputStream
     DataInputStream in = new DataInputStream(fstream);
     BufferedReader br = new BufferedReader(new InputStreamReader(in));
     String strLine;
     //Read File Line By Line
     while ((strLine = br.readLine()) != null) {
        // Print the content on the console
        System.out.println (strLine);
     }
     //Close the input stream
     in.close();
  }
  catch (Exception e){//Catch exception if any
     System.err.println("Error: " + e.getMessage());
  }
}

Can anyone guide me to the proper way of doing this.

  • 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-05T05:39:39+00:00Added an answer on June 5, 2026 at 5:39 am

    Your code will probably work, because you’re only loading each line into memory. You’ll lose the output in the stdout buffer once it’s read more than a few hundred lines, though.

    The best thing to do for comparison is to load a number of items into a collection, then throw away the ones you don’t need when you’re done with them. This will keep memory usage low. If you want to be clever about it, keep an eye on your process’s memory usage and start clearing out when it reaches a fixed threshold.

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

Sidebar

Related Questions

I would like to read a contact list without using intent or content provider,
I would like to read some characters from a string s1 and put it
I read two QStrings (ValueOne,ValueTwo) out of a file with (just a basic example)
I'm writing a program which is supposed to read two strings that can contain
I have two functions—one that builds the path to a set of files and
I have two asp.net applications on one IIS server and I would like to
I would like to read a (fairly big) log file into a MATLAB string
In java i would read the whole file in to byte array and do
I'm working on a Boggle game solver that would read lines of a text
I'm trying to build a simple GAE application that would read a textbox, pass

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.