aspose file tools*
The moose likes Beginning Java and the fly likes FileReader progress Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "FileReader progress" Watch "FileReader progress" New topic
Author

FileReader progress

Dylan Margoczi
Ranch Hand

Joined: Jul 12, 2007
Posts: 38
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Bill Cruise
Ranch Hand

Joined: Jun 01, 2007
Posts: 148
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

Joined: Jul 12, 2007
Posts: 38


Sweet sweet guys....
thats perfect

thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FileReader progress