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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:57:19+00:00 2026-05-26T17:57:19+00:00

Using java.net, java.io, what is the fastest way to parse html from online, and

  • 0

Using java.net, java.io, what is the fastest way to parse html from online, and load it to a file or the console? Is buffered writer/buffered reader faster than inputstreamreader/outputstreamwriter? Are writers and readers faster than outputstreams and inputstreams?
I am experiencing serious lag with the following output writer/stream:

URLConnection ii;
BufferedReader iik = new BufferedReader(new InputStreamReader(ii.getInputStream()));

String op;

while(iik.readLine()!=null) {
    op=iik.readLine();
    System.out.println(op);
}   

But curiously i am experiencing close to no lagtime with the following code:

URLConnection ii=i.openConnection();
Reader xh=new InputStreamReader(ii.getInputStream());

int r;
Writer xy=new PrintWriter(System.out);

while((r=xh.read())!=-1) {
    xy.write(r);
}  

xh.close();
xy.close();

What is going on here?

  • 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-26T17:57:20+00:00Added an answer on May 26, 2026 at 5:57 pm

    Readers/Writers shouldn’t be inherently faster than Input/OutputStreams.

    That said, going through readLine() and println() probably isn’t the optimal way of transferring bytes. In your case, if the file you’re loading doesn’t contain many newline characters, BufferedReader will have to buffer a lot of data before readLine() will return.

    The canonical non-terrible way of transferring data between streams is doing it in chunks by using a buffer:

    byte[] buf = new byte[1<<12];
    InputStream in = urlConnection.getInputStream();
    int read = -1;
    
    while ((read = in.read(buf) != -1) {
        System.out.write(buf, 0, read);
    }
    

    It might be faster yet to use NIO, the code for it is a little less straightforward and I just use the one found in this blog post.

    If you’re writing to/from a file, the best method is to use a zero-copy approach, which Java makes available with FileChannel.transferFrom() and transferTo(). Sample code is available in a DeveloperWorks article.

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

Sidebar

Related Questions

I'm trying to modify a file in a zip-file using java.util.net As direct modification
I am using iTextSharp in VB.net. I have this piece of code from java
I was using the java.net.URL.openStream() method to retrieve content from the server. I recently
I'm trying to download a gzipped file (~390Mo) from a FTP file using java.
I get the following warning when using java.net.URLEncoder.encode : warning: [deprecation] encode(java.lang.String) in java.net.URLEncoder
Using J2SE, I tried making a LAN application using java.net.*, and it worked perfectly.
I always designed/developed/released a software or web project myself/independent activity using java/vb.net and php
What is the event handler in Java (using net beans, Swing) that resembles the
What is the event handler in Java (using net beans) that resembles the From_Load
I'm trying to check if asp.net textbox is empty or not using java script.

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.