Java Code Examples for com.blankj.utilcode.util.FileUtils#delete()

The following examples show how to use com.blankj.utilcode.util.FileUtils#delete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetWorkMonitorFragment.java    From DoraemonKit with Apache License 2.0 6 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    //保存白名单
    List<WhiteHostBean> hostBeans = mHostAdapter.getData();
    if (hostBeans.size() == 1 && TextUtils.isEmpty(hostBeans.get(0).getHost())) {
        DokitConstant.WHITE_HOSTS.clear();
        FileUtils.delete(whiteHostPath);
        return;
    }
    DokitConstant.WHITE_HOSTS.clear();
    DokitConstant.WHITE_HOSTS.addAll(hostBeans);
    String hostArray = GsonUtils.toJson(hostBeans);
    //保存到本地
    FileUtils.delete(whiteHostPath);
    FileIOUtils.writeFileFromString(whiteHostPath, hostArray);
    //ToastUtils.showShort("host白名单已保存");

}
 
Example 2
Source File: FileOperator.java    From Pixiv-Shaft with MIT License 5 votes vote down vote up
@Override
public void clearAll() {
    if (FileUtils.delete(PathUtils.getInternalAppCachePath())) {
        ToastUtils.showShort("清除成功!");
    } else {
        ToastUtils.showShort("清除失败!");
    }
}
 
Example 3
Source File: ClearCacheDebug.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
private ThreadUtils.SimpleTask<Long> createClearCacheTask() {
    return new ThreadUtils.SimpleTask<Long>() {
        @Override
        public Long doInBackground() throws Throwable {
            try {
                long len = 0;
                File appDataDir = new File(PathUtils.getInternalAppDataPath());
                if (appDataDir.exists()) {
                    String[] names = appDataDir.list();
                    for (String name : names) {
                        if (!name.equals("lib")) {
                            File file = new File(appDataDir, name);
                            len += FileUtils.getLength(file);
                            FileUtils.delete(file);
                            LogUtils.i("「" + file + "」 was deleted.");
                        }
                    }
                }
                String externalAppCachePath = PathUtils.getExternalAppCachePath();
                len += FileUtils.getLength(externalAppCachePath);
                FileUtils.delete(externalAppCachePath);
                LogUtils.i("「" + externalAppCachePath + "」 was deleted.");
                return len;
            } catch (Exception e) {
                ToastUtils.showLong(e.toString());
                return -1L;
            }
        }

        @Override
        public void onSuccess(Long result) {
            if (result != -1) {
                ToastUtils.showLong("Clear Cache: " + ConvertUtils.byte2FitMemorySize(result));
            }
        }
    };
}