I currently have a program which reads from a text file and then writes to a database after each line it reads, the size of the text file is undetermined, some days the file could be more or less lines than other days.
I already have a swing worker that executes my functions so my progress bar works but right now I just have setIndeterminate to true so the user knows something is being done just not the actual progress.
Is there a way I can increment the progress bar after each line is read, but have it not reach 100 too early or too late, preferably without reading the the text file entirely before hand. Thanks, Beef.
I'd use File.length() to determine the file size. Then keep track of the number of bytes read to determine the progress.
If the file size is known before you are starting to read it you can read it line-by-line and count the percentage after every line: count the number of bytes in each line and devide it by the total number of bytes (i.e. file.length()).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With