当前位置: 首页>>代码示例>>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;未经允许,请勿转载。