80,490
社区成员
发帖
与我相关
我的任务
分享File a = new File(fromPath);
if (!a.exists()) {
toastStr = "拷贝文件不存在";
mHandler.sendEmptyMessage(showToatStr_10);
return;
}
String[] file = a.list();
File temp = null;
for (int i = 0; i < file.length; i++) {
if (stopStat) {
return;
}
if (fromPath.endsWith(File.separator)) {
fromFilePath = fromPath + file[i];
} else {
fromFilePath = fromPath + "/" + file[i];
}
temp = new File(fromFilePath);
toFilePath = toPath + "/" + file[i];
if (temp.isFile()) {
if (mode.equals("copy")) {
statTxtViewStr = "正在拷贝:" + fromFilePath;
mHandler.sendEmptyMessage(setStatTextView_3);
long FileIputStartTime = System.currentTimeMillis();
FileInputStream input = new FileInputStream(temp);
FileOutputStream output = new FileOutputStream(toPath
+ "/" + (temp.getName().toString()));
long FileIputEndTime = System.currentTimeMillis();
byte[] b = new byte[1024 * 80];
int len;
long whileStartTime = System.currentTimeMillis();
while ((len = input.read(b)) != -1) {
if (stopStat) {
output.flush();
output.close();
input.close();
return;
}
output.write(b, 0, len);
j += len;
prcJ = GetFileSize.FormetFileSize(j);
percent = (double) j * 100 / (double) temLong;
BigDecimal apct = new BigDecimal(percent);
newPct = apct.setScale(2, BigDecimal.ROUND_HALF_UP)
.doubleValue();
Message msg = mHandler.obtainMessage();
msg.arg1 = theNum;
msg.what = refreshSpeedListView_7;
msg.sendToTarget();
}
long whilEndTime = System.currentTimeMillis();
output.flush();
output.close();
input.close();
}public void getCopySpeed(int theNum) {
int num = 0;
newPct = 0;// 重置拷贝进度,排除上次拷贝所留下来的影响
while (!stopStat) {
if ((Double.toString(newPct)).equals("100.0")) {
return;
}
num += 1;
DecimalFormat df = new DecimalFormat("#.00");
copyspeed = (double) j * 10 / (double) (num);
if (copyspeed < 1) {
copySpeedStr = "0"
+ df.format((double) copyspeed / (1024 * 1024));
} else {
copySpeedStr = df.format((double) copyspeed / (1024 * 1024));//最后显示的拷贝速度,单位MB/S
}
Message msg = mHandler.obtainMessage();
msg.arg1 = theNum;
msg.what = refreshSpeedListView_7;
msg.sendToTarget();
SystemClock.sleep(100);
}public void itemCopy(final int itmID) {
String fromPath = alist.get(itmID).get("listViewFrom").toString();
String toPath = alist.get(itmID).get("listViewTo").toString();
step = "拷贝中……";
/**
* 新开一个线程,来计算拷贝速度
*/
new Thread(new Runnable() {
@Override
public void run() {
getCopySpeed(itmID);
}
}).start();
copyOrCompare("copy", fromPath, toPath, itmID);// 开始复制
}版主大大,可以具体一点么?我新手一个 遍历索引的问题
遍历索引的问题