本文整理汇总了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");
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
}
示例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);
}
示例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());
}