當前位置: 首頁>>代碼示例>>Java>>正文


Java File.getTotalSpace方法代碼示例

本文整理匯總了Java中java.io.File.getTotalSpace方法的典型用法代碼示例。如果您正苦於以下問題:Java File.getTotalSpace方法的具體用法?Java File.getTotalSpace怎麽用?Java File.getTotalSpace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.File的用法示例。


在下文中一共展示了File.getTotalSpace方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: compareZeroExist

import java.io.File; //導入方法依賴的package包/類
private static void compareZeroExist() {
    try {
        File f = File.createTempFile("tmp", null, new File("."));

        long [] s = { f.getTotalSpace(), f.getFreeSpace(), f.getUsableSpace() };

        for (int i = 0; i < s.length; i++) {
            if (s[i] == 0L)
                fail(f.getName(), s[i], "==", 0L);
            else
                pass();
        }
    } catch (IOException x) {
        fail("Couldn't create temp file for test");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:GetXSpace.java

示例2: getDiskPartitionSpaceUsedPercent

import java.io.File; //導入方法依賴的package包/類
/**
 * 獲取磁盤分區空間使用率
 */
public static double getDiskPartitionSpaceUsedPercent(final String path) {
    if (null == path || path.isEmpty())
        return -1;

    try {
        File file = new File(path);

        if (!file.exists())
            return -1;

        long totalSpace = file.getTotalSpace();

        if (totalSpace > 0) {
            long freeSpace = file.getFreeSpace();
            long usedSpace = totalSpace - freeSpace;

            return usedSpace / (double) totalSpace;
        }
    } catch (Exception e) {
        return -1;
    }

    return -1;
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:28,代碼來源:UtilAll.java

示例3: getDiskPartitionSpaceUsedPercent

import java.io.File; //導入方法依賴的package包/類
public static double getDiskPartitionSpaceUsedPercent(final String path) {
    if (null == path || path.isEmpty())
        return -1;

    try {
        File file = new File(path);
        if (!file.exists()) {
            boolean result = file.mkdirs();
            if (!result) {
                // TODO
            }
        }

        long totalSpace = file.getTotalSpace();
        long freeSpace = file.getFreeSpace();
        long usedSpace = totalSpace - freeSpace;
        if (totalSpace > 0) {
            return usedSpace / (double) totalSpace;
        }
    }
    catch (Exception e) {
        return -1;
    }

    return -1;
}
 
開發者ID:y123456yz,項目名稱:reading-and-annotate-rocketmq-3.4.6,代碼行數:27,代碼來源:UtilAll.java

示例4: createSignature

import java.io.File; //導入方法依賴的package包/類
private static String createSignature(File dir) {
	List<String> fileNames = new ArrayList<String>();
	File files[] = dir.listFiles();
	if (files!=null) {
		for(File file : files) fileNames.add(file.getName());
	}

	Collections.sort(fileNames);
	StringBuffer fileNamesText = new StringBuffer();
	for(String fileName : fileNames) {
		fileNamesText.append(fileName);
	}

	Log.d(LOGTAG, "signature for root " + dir.getAbsolutePath() + " input " + fileNamesText.toString());
	String signature = Utils.md5(fileNamesText.toString()) + "." + dir.getTotalSpace();
	Log.d(LOGTAG, "signature for root " + dir.getAbsolutePath() + " = " + signature);
	return signature;
}
 
開發者ID:fcatrin,項目名稱:retroxlibs,代碼行數:19,代碼來源:DriveUtils.java

示例5: setGoodDirsDiskUtilizationPercentage

import java.io.File; //導入方法依賴的package包/類
private void setGoodDirsDiskUtilizationPercentage() {

    long totalSpace = 0;
    long usableSpace = 0;

    for (String dir : localDirs) {
      File f = new File(dir);
      if (!f.isDirectory()) {
        continue;
      }
      totalSpace += f.getTotalSpace();
      usableSpace += f.getUsableSpace();
    }
    if (totalSpace != 0) {
      long tmp = ((totalSpace - usableSpace) * 100) / totalSpace;
      if (Integer.MIN_VALUE < tmp && Integer.MAX_VALUE > tmp) {
        goodDirsDiskUtilizationPercentage = (int) tmp;
      }
    } else {
      // got no good dirs
      goodDirsDiskUtilizationPercentage = 0;
    }
  }
 
開發者ID:naver,項目名稱:hadoop,代碼行數:24,代碼來源:DirectoryCollection.java

示例6: getDiskPartitionSpaceUsedPercent

import java.io.File; //導入方法依賴的package包/類
public static double getDiskPartitionSpaceUsedPercent(final String path) {
    if (null == path || path.isEmpty())
        return -1;

    try {
        File file = new File(path);

        if (!file.exists())
            return -1;

        long totalSpace = file.getTotalSpace();

        if (totalSpace > 0) {
            long freeSpace = file.getFreeSpace();
            long usedSpace = totalSpace - freeSpace;

            return usedSpace / (double) totalSpace;
        }
    } catch (Exception e) {
        return -1;
    }

    return -1;
}
 
開發者ID:lyy4j,項目名稱:rmq4note,代碼行數:25,代碼來源:UtilAll.java

示例7: compare

import java.io.File; //導入方法依賴的package包/類
private static void compare(Space s) {
    File f = new File(s.name());
    long ts = f.getTotalSpace();
    long fs = f.getFreeSpace();
    long us = f.getUsableSpace();

    out.format("%s:%n", s.name());
    String fmt = "  %-4s total= %12d free = %12d usable = %12d%n";
    out.format(fmt, "df", s.total(), 0, s.free());
    out.format(fmt, "getX", ts, fs, us);

    // if the file system can dynamically change size, this check will fail
    if (ts != s.total())
        fail(s.name(), s.total(), "!=", ts);
    else
        pass();

    // unix df returns statvfs.f_bavail
    long tsp = (!name.startsWith("Windows") ? us : fs);
    if (!s.woomFree(tsp))
        fail(s.name(), s.free(), "??", tsp);
    else
        pass();

    if (fs > s.total())
        fail(s.name(), s.total(), ">", fs);
    else
        pass();

    if (us > s.total())
        fail(s.name(), s.total(), ">", us);
    else
        pass();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:35,代碼來源:GetXSpace.java

示例8: check

import java.io.File; //導入方法依賴的package包/類
public String check(String folder) {
  if (folder == null)
    throw new IllegalArgumentException("folder");
  File f = new File(folder);

  folderSize = getFileSize(f);
  usage = 1.0*(f.getTotalSpace() - f.getFreeSpace())/ f.getTotalSpace();
  return String.format("used %d files %d disk in use %f", folderSize, fileCount, usage);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:10,代碼來源:DUHelper.java

示例9: GetMinimumDirSize

import java.io.File; //導入方法依賴的package包/類
public static long GetMinimumDirSize(File file)
{
	long result = 0;
	for( File f : file.listFiles()) {
		if(f.isFile()) {
			result += f.length();
		} else if(f.isDirectory()) {
			result += f.getTotalSpace();
		}
	}
	return result;
}
 
開發者ID:adityak368,項目名稱:Android-FileBrowser-FilePicker,代碼行數:13,代碼來源:AssortedUtils.java

示例10: init

import java.io.File; //導入方法依賴的package包/類
@PostConstruct
public void init() {
    long totalSpace = 0;
    try {
        File file = new File(Constants.DOWNLOAD_HOME);
        totalSpace = file.getTotalSpace();
    } catch (Exception e) {
    }
    long youngGcThreshold = totalSpace > 0 && totalSpace / 4 < 100 * 1024 * 1024 * 1024L ? totalSpace / 4
        : 100 * 1024 * 1024 * 1024L;
    downSpaceCleaner.fillConf(DownSpaceCleaner.SPACE_TYPE_DISK, Constants.DOWNLOAD_HOME,
        5 * 1024 * 1024 * 1024L,
        youngGcThreshold, 1, 2 * 3600 * 1000L);
}
 
開發者ID:alibaba,項目名稱:Dragonfly,代碼行數:15,代碼來源:DiskSpaceGcTimer.java

示例11: getExternalImageCacheDir

import java.io.File; //導入方法依賴的package包/類
public static String getExternalImageCacheDir(Context context) {
    String coolcloudDir = System.getProperty("file.separator") + context.getPackageName() + System.getProperty("file.separator");
    String androidDataDir = System.getProperty("file.separator") + "Android" + System.getProperty("file.separator") + ShareRequestParam.RESP_UPLOAD_PIC_PARAM_DATA;
    String externalCacheDir = null;
    String[] paths = getVolumePaths(context);
    if (paths != null && paths.length >= 2) {
        if (paths[1].contains("udisk")) {
            if (1 == isSdcardMounted(paths[0], context)) {
                externalCacheDir = paths[0] + androidDataDir + coolcloudDir;
            }
        } else if (1 == isSdcardMounted(paths[1], context)) {
            externalCacheDir = paths[1] + androidDataDir + coolcloudDir;
        }
    }
    if (externalCacheDir == null) {
        if (Environment.getExternalStorageState().equals("mounted")) {
            externalCacheDir = Environment.getExternalStorageDirectory().getPath() + androidDataDir + coolcloudDir;
        } else {
            File file = context.getFilesDir();
            String udiskDir = file.getAbsolutePath();
            if (VERSION.SDK_INT > 8) {
                if (file != null && file.exists() && file.getTotalSpace() > 0) {
                    externalCacheDir = udiskDir + androidDataDir + coolcloudDir;
                }
            } else if (file != null && file.isDirectory()) {
                externalCacheDir = udiskDir + androidDataDir + coolcloudDir;
            }
        }
    }
    if (externalCacheDir == null) {
        return "";
    }
    new File(externalCacheDir).mkdirs();
    return externalCacheDir;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:36,代碼來源:SystemUtils.java

示例12: getFTPInfo

import java.io.File; //導入方法依賴的package包/類
/**
 * 獲取FTP信息
 *
 * @return FTP信息
 * @throws FtpException FTP異常
 */
public FTPInfo getFTPInfo() throws FtpException {
    User userInfo = um.getUserByName(um.getAdminName());
    TransferRateRequest transferRateRequest = (TransferRateRequest) userInfo
            .authorize(new TransferRateRequest());
    File homeDir = Paths.get(userInfo.getHomeDirectory()).toFile();
    long totalSpace = homeDir.getTotalSpace();
    long usedSpace = totalSpace - homeDir.getUsableSpace();

    return new FTPInfo(host, port, homeDir.getAbsolutePath(),
            transferRateRequest.getMaxDownloadRate() / 1024,
            transferRateRequest.getMaxUploadRate() / 1024,
            usedSpace, totalSpace);
}
 
開發者ID:wyp0596,項目名稱:ftp-server,代碼行數:20,代碼來源:MyFtpServer.java

示例13: getRootOfInnerSdCardFolder

import java.io.File; //導入方法依賴的package包/類
private static String getRootOfInnerSdCardFolder(File file)
{
    if(file==null)
        return null;
    final long totalSpace=file.getTotalSpace();
    while(true)
    {
        final File parentFile=file.getParentFile();
        if(parentFile==null||parentFile.getTotalSpace()!=totalSpace)
            return file.getAbsolutePath();
        file=parentFile;
    }
}
 
開發者ID:GlennioTech,項目名稱:MetadataEditor,代碼行數:14,代碼來源:EStorageItemsLister.java

示例14: isDiskUsageOverPercentageLimit

import java.io.File; //導入方法依賴的package包/類
private boolean isDiskUsageOverPercentageLimit(File dir) {
  float freePercentage =
      100 * (dir.getUsableSpace() / (float) dir.getTotalSpace());
  float usedPercentage = 100.0F - freePercentage;
  return (usedPercentage > diskUtilizationPercentageCutoff
      || usedPercentage >= 100.0F);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:8,代碼來源:DirectoryCollection.java

示例15: getStatus

import java.io.File; //導入方法依賴的package包/類
@Override
public FsStatus getStatus(Path p) throws IOException {
  File partition = pathToFile(p == null ? new Path("/") : p);
  //File provides getUsableSpace() and getFreeSpace()
  //File provides no API to obtain used space, assume used = total - free
  return new FsStatus(partition.getTotalSpace(), 
    partition.getTotalSpace() - partition.getFreeSpace(),
    partition.getFreeSpace());
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:10,代碼來源:RawLocalFileSystem.java


注:本文中的java.io.File.getTotalSpace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。