This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileReader progress

 
Dylan Margoczi
Ranch Hand
Posts: 38
  • 0
  • 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: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • 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
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Sweet sweet guys....
thats perfect

thanks
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic