How to create an accurate progress bar with an unknown length?

If I read the file until it hits the zero line and wants to create a somewhat accurate JProgressBar when the reading is complete, how would I do it?

I ask because some files are read inside 200ms, where others take between 2500msand 10000ms.

I am doing something simple to read a file

boolean completed

while(!completed) {
    //read file
    if(reader == null) {
        completed = false;
    } 
}

So, is there a way to make the progress indicator accurate for such a situation? (by the way, the file size does not necessarily mean that in this case it will take less time to read)

+3
source share
1 answer

Use file size - this is your best measure.

, , , . . , , , . , .

, . - , , . , , , , , , . , ! , , , , , .

- . , ( ) . , , , . , , , , , , .

, "25% , 3 , 9 ". , , , .

+6
source

All Articles