1

当我在 Android 中将文件 A复制到文件夹 B时,我想使用ProgressDialog(ProgressDialog.STYLE_HORIZONTAL).

示例 1:

String mStart = "/sdcard/aaaa/";    
FileInputStream fis = new FileInputStream(mStart);    
FileOutputStream fos = new FileOutputStream(path);  

FileChannel fin = fis.getChannel();
FileChannel fout = fos.getChannel();    
File f = new File(mStart);

fin.transferTo(0, f.length(), fout);    

示例 2:

byte[] buffer = new byte[1024];    
while ((readcount = bin.read(buffer, 0, 1024)) != -1) {    
    bout.write(buffer, 0, readcount);    
    publishProgress(readcount);    
}

如果我使用第二个示例,我可以使用ProgressDialog(),但在第一个示例中我不能。ProgressDialog使用方法时如何更新transferTo()

4

0 回答 0