com.blankj.utilcode.util.FileIOUtils Java Examples
The following examples show how to use
com.blankj.utilcode.util.FileIOUtils.
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 |
private void initCustomView() { findViewById(R.id.btn_net_summary).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showContent(NetWorkMainPagerFragment.class); } }); mHostRv = findViewById(R.id.host_list); mHostRv.setLayoutManager(new LinearLayoutManager(getActivity())); if (DokitConstant.WHITE_HOSTS.isEmpty()) { String whiteHostArray = FileIOUtils.readFile2String(whiteHostPath); if (TextUtils.isEmpty(whiteHostArray)) { mHostBeans.add(new WhiteHostBean("", true)); } else { mHostBeans = GsonUtils.fromJson(whiteHostArray, GsonUtils.getListType(WhiteHostBean.class)); DokitConstant.WHITE_HOSTS.clear(); DokitConstant.WHITE_HOSTS.addAll(mHostBeans); } } else { mHostBeans.addAll(DokitConstant.WHITE_HOSTS); } mHostAdapter = new WhiteHostAdapter(R.layout.dk_item_white_host, mHostBeans); mHostRv.setAdapter(mHostAdapter); }
Example #2
Source File: NetWorkMonitorFragment.java From DoraemonKit with Apache License 2.0 | 6 votes |
@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 #3
Source File: SearchPresenterImpl.java From DanDanPlayForAndroid with MIT License | 6 votes |
@Override public void downloadTorrent(String magnet) { getView().showDownloadTorrentLoading(); MagnetBean.downloadTorrent(magnet, new CommOtherDataObserver<ResponseBody>() { @Override public void onSuccess(ResponseBody responseBody) { String downloadPath = getView().getDownloadFolder(); downloadPath += Constants.DefaultConfig.torrentFolder; downloadPath += "/" + magnet.substring(20) + ".torrent"; FileIOUtils.writeFileFromIS(downloadPath, responseBody.byteStream()); getView().dismissDownloadTorrentLoading(); getView().downloadTorrentOver(downloadPath, magnet); } @Override public void onError(int errorCode, String message) { getView().dismissDownloadTorrentLoading(); LogUtils.e(message); ToastUtils.showShort("下载种子文件失败"); } }, new NetworkConsumer()); }
Example #4
Source File: DataPickManager.java From DoraemonKit with Apache License 2.0 | 5 votes |
/** * 异常情况下保存到本地保存到本地 */ public void saveData2Local() { if (events == null || events.size() == 0) { return; } dataPickBean.setEvents(events); //保存数据到本地 FileIOUtils.writeFileFromString(filePath, GsonUtils.toJson(dataPickBean)); }
Example #5
Source File: ShooterSubDetailBean.java From DanDanPlayForAndroid with MIT License | 5 votes |
public static void downloadSubtitle(String downloadLink, String filePath, boolean unzip, CommShooterDataObserver<String> observer, NetworkConsumer consumer) { RetroFactory.getShooterInstance().downloadSubtitle(downloadLink) .map(responseBody -> { if (!FileIOUtils.writeFileFromIS(filePath, responseBody.byteStream())) { throw new IOException("写入文件失败"); } return true; }) .flatMap(unzipFile(unzip, filePath)) .doOnSubscribe(consumer) .compose(ShooterNetworkUtils.network()) .subscribe(observer); }
Example #6
Source File: UtilsApp.java From Android-UtilCode with Apache License 2.0 | 5 votes |
private void initAssets() { if (!FileUtils.isFileExists(Config.getTestApkPath())) { try { FileIOUtils.writeFileFromIS(Config.getTestApkPath(), getAssets().open("test_install.apk"), false); } catch (IOException e) { e.printStackTrace(); } } }
Example #7
Source File: AppStartInfoFragment.java From DoraemonKit with Apache License 2.0 | 4 votes |
/** * 将启动信息保存到文件并分享 */ private void export2File(final String info) { if (TextUtils.isEmpty(info)) { ToastUtils.showShort("启动信息为空"); return; } ToastUtils.showShort("启动信息保存中,请稍后..."); final String logPath = PathUtils.getInternalAppFilesPath() + File.separator + AppUtils.getAppName() + "_" + "app_launch.log"; final File logFile = new File(logPath); ThreadUtils.executeByCpu(new ThreadUtils.Task<Boolean>() { @Override public Boolean doInBackground() throws Throwable { try { FileIOUtils.writeFileFromString(logFile, info, false); return true; } catch (Exception e) { e.printStackTrace(); return false; } } @Override public void onSuccess(Boolean result) { if (result) { ToastUtils.showShort("启动信息文件保存在:" + logPath); //分享 FileUtil.systemShare(DoraemonKit.APPLICATION, logFile); } } @Override public void onCancel() { if (logFile.exists()) { FileUtils.delete(logFile); } ToastUtils.showShort("启动信息保存失败"); } @Override public void onFail(Throwable t) { if (logFile.exists()) { FileUtils.delete(logFile); } ToastUtils.showShort("启动信息保存失败"); } }); }
Example #8
Source File: LogInfoDokitView.java From DoraemonKit with Apache License 2.0 | 4 votes |
/** * 将日志信息保存到文件 * * @param operateType 100 保存到本地 101 保存到本地并分享 */ private void export2File(final int operateType) { ToastUtils.showShort("日志保存中,请稍后..."); final String logPath = PathUtils.getInternalAppFilesPath() + File.separator + AppUtils.getAppName() + "_" + TimeUtils.getNowString(new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss")) + ".log"; final File logFile = new File(logPath); ThreadUtils.executeByCpu(new ThreadUtils.Task<Boolean>() { @Override public Boolean doInBackground() throws Throwable { try { List<LogLine> logLines = new ArrayList<>(mLogItemAdapter.getTrueValues()); for (LogLine logLine : logLines) { String strLog = logLine.getProcessId() + " " + " " + logLine.getTimestamp() + " " + logLine.getTag() + " " + logLine.getLogLevelText() + " " + logLine.getLogOutput() + "\n"; FileIOUtils.writeFileFromString(logFile, strLog, true); } return true; } catch (Exception e) { e.printStackTrace(); return false; } } @Override public void onSuccess(Boolean result) { if (result) { ToastUtils.showShort("文件保存在:" + logPath); //分享 if (operateType == 101) { FileUtil.systemShare(DoraemonKit.APPLICATION, logFile); } } } @Override public void onCancel() { if (logFile.exists()) { FileUtils.delete(logFile); } ToastUtils.showShort("日志保存失败"); } @Override public void onFail(Throwable t) { if (logFile.exists()) { FileUtils.delete(logFile); } ToastUtils.showShort("日志保存失败"); } }); }