我正在使用Apache commons库将文件从一个目录复制到另一个目录。我遇到的问题是我无法想出一种在复制文件时更新进度条的方法。我的初步想法是使用回调,但没有办法将回调传递给copyfile方法。
FileUtils.copyFileToDirectory(fileSrc, fileDest);
答案 0 :(得分:0)
我解决了我的问题如下,可能对你有用。
if (mAdapter != null && mAdapter.getItemCount() > 0) {
final ArrayList<StoryModel> selectedList = mAdapter.getSelectedData();
if (selectedList.size() > 0) {
final ProgressDialog pd = new ProgressDialog(getActivity());
pd.setMessage("Saving Stories....");
pd.show();
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
for (StoryModel imageModel : selectedList) {
String srcFilePath = imageModel.getUrl();
Log.d(TAG, "onOptionsItemSelected: " + srcFilePath);
org.apache.commons.io.FileUtils.copyFileToDirectory(new File(srcFilePath), new File(FileUtils.getAppPath(mContext)));
}
} catch (IOException ignored) {
}
Log.d(TAG, "run: Dismissed....");
pd.dismiss();
}
});
t.start();
} else {
Toast.makeText(mContext, R.string.string_error_select_story_to_download, Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(mContext, R.string.string_error_select_story_to_download, Toast.LENGTH_LONG).show();
}
谢谢:)