Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileReader progress

 
Dylan Margoczi
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

I want to have a progress bar in my gui that will show the status of a file being read/written. I read/write the file one line at a time, the problem is I don't know how many lines there are to begin with so i can't make a comparison for the progress bar.

Help me....
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "length()" method in java.io.File will tell you the size of a file; from this you can estimate the number of lines to use for your reading progress bar.

For writing to the file, you need to come up with your own way to estimate how much data is left to write, based on your knowledge of what the data is.
 
Bill Cruise
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't know how many lines there are, but you do know how many bytes there are in the file. Keep track of how many bytes you've read (the length of each line) as you read lines, and use the ratio to update your progress bar.
 
Dylan Margoczi
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Sweet sweet guys....
thats perfect

thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic