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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:38:19+00:00 2026-06-02T14:38:19+00:00

I want to find the size of an HTML file without HTTP headers and

  • 0

I want to find the size of an HTML file without HTTP headers and data transfer rate. Below is my code;

import java.net.*;
import java.io.*;

public class HttpCon 
{
  public static void main ( String[] args ) throws IOException 
  {
    Socket s = null;

    try 
    {
        String host = "host1";
        String file = "file1";
        int port = 80;

        s = new Socket(host, port);

        OutputStream out = s.getOutputStream();
        PrintWriter outw = new PrintWriter(out, false);
        outw.print("GET " + file + " HTTP/1.1\r\n");
        outw.print("Host: " + host + ":" + port + "\r\n");
        outw.print("Accept: text/plain, text/html, text/*\r\n");
        outw.print("\r\n");
        outw.flush();           

        InputStream in = s.getInputStream();
        InputStreamReader inr = new InputStreamReader(in);
        BufferedReader br = new BufferedReader(inr);
        String line;

        while ((line = br.readLine()) != null) 
        {
                System.out.println(line);
        }
        br.close();       

    } 

  }
} 

But I do not have any idea how to do this. Is there a source code that I can look at or any resource that I can apply?

Any help will be appreciated, thanks in advance.

  • 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-02T14:38:21+00:00Added an answer on June 2, 2026 at 2:38 pm

    What you are asking for shouldn’t be much of a problem. Read the lines until you read an empty line — that’s where the headers end. After that just go on reading and count all the characters you have read and that’s your file size. As for transfer rate:

    final long start = System.nanoTime();
    long charsRead = 0;
    ... do the transfer, counting chars ...
    System.out.println("Transfer rate: " + 
      (charsRead / (1e-6 * (System.nanoTime() - start))));
    

    The only problem here will be that you are using a BufferedReader so you count chars and not bytes. If you need bytes, then you’ll need to use the raw InputStream and then it’s going to be a slight pain in the butt to find where the headers end. You can get around that (probably) by using not the BufferedReader but the InputStreamReader, which will not read-ahead anything. When you find the end of headers, switch to the raw InputStream to read the response body.

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

Sidebar

Related Questions

I want to quickly find the total size of any folder using python. import
I am parsing an html file and I want to find the part of
I want to change the view size for iPhone 3.0, but I find that
I want to find a way to copy one file to multiple locations simultaneously
I can't find any solution to this problem. Here's the render I want: http://jsfiddle.net/kQSxb/
I want to calculate the cell height using code. My text contains html entities
I want find all Saturdays and Sundays in A given month. How can I
I want to find a struct in a vector, but I'm having some troubles.
I want to find the sum and count of specific values in my table.
I want to find out the position of an element which is in iframe.

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.