i hope you are fine. i have here a code i took it from this site, for copy files from path to path. i want to use a progressBar with it, how do i use the progressBar with the counter?
i used the bellow code, and there's is no progress in progressBar ! this is the code :
progressbar1 = (ProgressBar) findViewById(R.id.progressbar1);
progressbar1.setMax((int)100);
java.io.File filein = new java.io.File("/storage/emulated/0/Alarms/test.zip");
java.io.File fileout = new java.io.File("/storage/emulated/0/testcopied.zip");
java.io.FileInputStream fin = null;
java.io.FileOutputStream fout = null;
long length = filein.length();
long counter = 0;
int r = 0;
byte[] b = new byte[1024];
try {
fin = new java.io.FileInputStream(filein);
fout = new java.io.FileOutputStream(fileout);
while( (r = fin.read(b)) != -1) {
counter += r;
int k = (int)counter;
progressbar1.setProgress((int)k);
System.out.println( 1.0 * counter / length );
fout.write(b, 0, r);
}
}
catch(Exception e){
System.out.println("foo");
}