determine the encrypted file size

P

Peter

Hi
I use the following code to encrypt a file. How can i determine the size
of the file after encrypt? Because i want to set up a progress bar.

FileInputStream in = new FileInputStream(new
File("file.txt"));
FileOutputStream fileOut = new
FileOutputStream("newfile.txt");

CipherOutputStream out = new CipherOutputStream(fileOut,
encryptCipher);

byte[] buffer = new byte[1024];
int length;
while ( (length = in.read(buffer)) != -1) {
out.write(buffer, 0, length);
}


thanks
from Peter ([email protected])
 
R

Roedy Green

I use the following code to encrypt a file. How can i determine the size
of the file after encrypt? Because i want to set up a progress bar.

You can't, but you can do some samples and get an estimate of the
bloat factor.

You can also do your progress based on how much you have encrypted,
not the final size.
 
A

ak

I use the following code to encrypt a file. How can i determine the
size
of the file after encrypt? Because i want to set up a progress bar.
use input, not output to determine progress
 
L

Liz

Too late, you are writing it as you create it, by the time
you know the length of the file it is already written, so
progress = "done";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top