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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:47:25+00:00 2026-05-27T20:47:25+00:00

I am reading a big file in a Java program, using http access. I

  • 0

I am reading a big file in a Java program, using http access. I read the stream, and then I apply some criteria. Would it be possible to apply the criteria on the read stream, so I will have a light result (I’m reading big files)?

Here is my code for reading the file:

public String getMyFileContent(URLConnection uc){
            String myresult = null;
            try {
                InputStream is = uc.getInputStream();
                InputStreamReader isr = new InputStreamReader(is);
                int numCharsRead;
                char[] charArray = new char[1024];
                StringBuffer sb = new StringBuffer();

                while ((numCharsRead = isr.read(charArray)) > 0) {
                    sb.append(charArray, 0, numCharsRead);
                }
                myresult = sb.toString();

            }
            catch (MalformedURLException e) {
                e.printStackTrace();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return result;  
}

And in another method, I then apply the criteria (to parse the content).
I couldn’t achieve to do like this:

public String getMyFileContent(URLConnection uc){
    String myresult = null;
    try {
        InputStream is = uc.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        int numCharsRead;
        char[] charArray = new char[1024];
        StringBuffer sb = new StringBuffer();

        while ((numCharsRead = isr.read(charArray)) > 0) {
            sb.append(charArray, 0, numCharsRead);
            //Apply my criteria here on the stream ??? Is it possible ???
        }
        myresult = sb.toString();
    }
    catch (MalformedURLException e) {
        e.printStackTrace();
    }
    catch (IOException e) {
        e.printStackTrace();
    }
    return myresult;
}
  • 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-27T20:47:26+00:00Added an answer on May 27, 2026 at 8:47 pm

    The template I would use is

    InputStreamReader isr = new InputStreamReader(uc.getInputStream());
    int numCharsRead;
    char[] charArray = new char[1024];
    
    while ((numCharsRead = isr.read(charArray)) > 0) {
        //Apply my criteria here on the stream
    }
    

    however since it is text, this might be more useful

    InputStream is = uc.getInputStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
    String line;
    
    while ((line = br.readLine()) != null) {
        //Apply my criteria here on each line
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading a big file using fread. When I interrupt the program during it
I need to read a big file by reading at most N lines at
I am reading a ZIP file using java as below: Enumeration<? extends ZipEntry> zes=zip.entries();
Looking at this question: Reading Remote MP3 File's ID3 Tags using Java It looks
I would like to read a (fairly big) log file into a MATLAB string
I have a big file transfer (say 4gb or so) and rather than using
In the comments to my answer about reading an entire file into memory using
In order to improve performance reading from a file, I'm trying to read the
I've written a cache manifest file for a big XML file I'm reading data
i have a big file in text format who i trying to read through

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.