Esempio n. 1
0
    /** 一次性,全部读取所有的信息 */
    private long getDirSize(File file) {
      long tempSize = ERROR_SIZE;
      long totalSize = ERROR_SIZE;

      File[] childFiles = file.listFiles();
      for (int i = 0; i < childFiles.length; i++) {
        if (childFiles[i].isDirectory()) {
          tempSize = getDirSize(childFiles[i]);
          totalSize += tempSize;
        } else {
          tempSize = FileSizeUtil.getFileSize(childFiles[i]);
          tempSize = tempSize == FileSizeUtil.getErrorSize() ? 0 : tempSize;
          totalSize += tempSize;

          resultBean.add(
              new FileBean(childFiles[i].getName(), childFiles[i].getAbsolutePath(), tempSize));
        }
      }

      // 储存目录的 信息
      resultBean.add(
          new FileBean(
              file.getName(),
              file.getAbsolutePath(),
              file.listFiles(FileUtil.getsDirFilter()).length,
              file.listFiles(FileUtil.getsFileFilter()).length,
              totalSize));

      return totalSize;
    }
Esempio n. 2
0
    @Override
    public void run() {
      startCache();

      String rootPath = FileUtil.getPath();
      long startTime = System.currentTimeMillis();
      LogFileUtil.v("rootPath = " + rootPath + ",startTime = " + startTime);

      if (null != rootPath) {
        final File rootFile = new File(rootPath);
        long size = getDirSize(rootFile);

        LogFileUtil.v(TAG, "DirSize = " + FileSizeUtil.formatFileAutoSize(size));
      } else {
        IApplication.toast("内存空间不存在");
        LogFileUtil.v(TAG, "rootPath is null");
      }

      LogFileUtil.v(
          TAG,
          "ReadTime = "
              + (System.currentTimeMillis() - startTime)
              + ",fileNumber = "
              + resultBean.size());
      startTime = System.currentTimeMillis();

      DbFileBeanManager.getInstance().insertAtSameMoment(resultBean);
      LogFileUtil.v(TAG, "WriteTime = " + (System.currentTimeMillis() - startTime));

      endCache();
    }