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

  • Home
  • SEARCH
  • 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 9009339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:09:54+00:00 2026-06-16T02:09:54+00:00

I am programming in Java. I want to count the size of all files

  • 0

I am programming in Java. I want to count the size of all files in a specific folder periodically. The period is not constant and is very short. My code is as follows:

//get Index Size
index_byte_size = 0;
File index = new File(indexPath);
String[] files = index.list();
File f = null;
for(int i=0; i < files.length; i++) {
    f = new File(index, files[i]);
    index_byte_size += f.length();
}

index_byte_size is what I want to get. indexPath is the path of the folder.

The code is in a loop. And I output the total index_byte_size after every loop. The file size should increase continually due to my knowledge. However, the result I get is just like this:

IndexSize(byte) Time(ms)
0   297
0   802
0   1293
0   1710
7769547 2952
7769547 4330
7769547 4431
7769547 4785
7769547 4901
7769547 5213
7769547 5279
7769547 5446
7769547 5660
7769547 5861
7769547 6155
24041054    8763
24041054    9203
24041054    10439
24041054    10820
24041054    11685
36708630    13662
36708630    14309
36708630    16065
36708630    16192
36708630    16374
36708630    16691
36708630    16899
...

As you can see, the file size just increases, and then stays constant, and then increases…. I don’t know what is happening and I guess there is something happening with the Operating System. My OS is Windows 7.


[Background]

I want to do a experiment with Lucene to see its indexing capacity, especially its index size and indexing efficiency.

I have a lot of little pieces of text files (each 2-10M size). And I want to see how long it takes Lucene to index each of them one by one, and how big the index will be. So I write this program.

I don’t want to be notified when the indices change (because of course they will change). I just what to know how long and how big they are in a very short period.


Does anyone know why? And how can I count the size corrcetly in a real-time manner?

  • 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-16T02:09:55+00:00Added an answer on June 16, 2026 at 2:09 am

    It is common for applications to buffer output and only push out data in lumps.

    I suspect this is not the case here. Instead I suspect Lucene is using memory mapped files. When you grow a memory mapped file, it grows with each allocation you make. As an allocation is expensive, but the cost of allocating more than you need rather cheap (as it uses virtual memory and only uses main memory and disk as you touch it) the most efficient thing to do is to allocate large blocks and then fill them up lazily. (E.g. I allocate 128 MB at a time with a 64-bit JVM)

    File.length gives you the extents of the file, not how much has actually been used or even how much disk space is used. You can see how much disk space has been used with du on unix and possibly some tool in Java 7 (I have only found the space used for file system roots, not files)

    Even so, this tells you how many pages have been touched. The only way to know accurately how much has been used is to read the file and this has limited accuracy if the file is being modified while you read it.

    EDIT: on Windows 7 the space appears to be reserved immediately so you cannot create a sparse file larger than the size of the file system (as you can on ext4 filesystems)

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

Sidebar

Related Questions

I'm programming Java in Eclipse IDE. Here is code I want to read file:
Programming language: Java Ok, so I want to have a BufferedImage that keeps rotating
I want to start with Comet programming in Java. What's the first step or
I'm new to Java programming. I want to write simple Java network protocol. I
My question is about angle functions in programming languge Java. if i want to
I am creating a chat application using java sockets programming. I want to launch
I have started programming a few weeks ago in java/android. I want to write
i am new in JavaScript programming i want java script to find the names
I'm new to Web java programming. I want to create a simple JSF modular
trying to learn windows programming in java, want to display a image to a

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.