当前位置: 首页>>代码示例>>Java>>正文


Java File.getFreeSpace方法代码示例

本文整理汇总了Java中java.io.File.getFreeSpace方法的典型用法代码示例。如果您正苦于以下问题:Java File.getFreeSpace方法的具体用法?Java File.getFreeSpace怎么用?Java File.getFreeSpace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.File的用法示例。


在下文中一共展示了File.getFreeSpace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: retrieveCacheDir

import java.io.File; //导入方法依赖的package包/类
private void retrieveCacheDir(final Context context) {
	final String tag="retrieveCacheDir - ";
	dirCache = null;
	if (isExternalStorageWritable()){
		final File dir=new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES),DIRECTORY_TILES_CACHE);
		if (!dir.exists()) {
			try {
				if (!dir.mkdirs()){
					Log.w(TAG,tag+"Not possible to create directory: "+ dir.getPath());
				} else {
					dirCache=dir;
				}
			} catch (SecurityException e){
				Log.w(TAG,tag+"Not possible to create directory: "+ dir.getPath(),e);
			}
		} else if (dir.getFreeSpace()<MIN_FREE_BYTES){
			Log.w(TAG,tag+"Not enough free space on external files dir. Minimal required: "+MIN_FREE_BYTES+" bytes.");
		} else {
			dirCache=dir;
		}
	}

	if (dirCache==null){
		Log.w(TAG,tag+"No external files directory available, use cache directory.");
		dirCache = context.getCacheDir();
	}
}
 
开发者ID:videgro,项目名称:Ships,代码行数:28,代码来源:HttpCacheTileServer.java

示例2: checkSpace

import java.io.File; //导入方法依赖的package包/类
private boolean checkSpace(long size) {
    File ftsDir = new File(NectarServerApplication.getConfiguration().getFtsDirectory());

    long usableSpace = (ftsDir.getFreeSpace() / 1000) / 1000;
    if(usableSpace <= NectarServerApplication.getConfiguration().getSpaceThreshold()) {
        NectarServerApplication.getLogger().warn("FTS Directory only has " + usableSpace + "MB of free space left!");
        return false;
    }

    long sizeMb = size / 1000 / 1000;
    if(usableSpace <= sizeMb) {
        NectarServerApplication.getLogger().warn("Rejected file upload of size " + sizeMb +": not enough space!");
        return false;
    }

    return true;
}
 
开发者ID:jython234,项目名称:nectar-server,代码行数:18,代码来源:FTSController.java

示例3: createTempFile

import java.io.File; //导入方法依赖的package包/类
/**
 * Create a temporary file in the cache directory on either internal or external storage,
 * whichever is available and has more free space.
 *
 * @param mimeType the MIME type of the file to create (image/*)
 */
private static File createTempFile(Context context, @Nullable String mimeType)
    throws IOException {
  File externalCacheDir = context.getExternalCacheDir();
  File internalCacheDir = context.getCacheDir();
  File cacheDir;
  if (externalCacheDir == null && internalCacheDir == null) {
    throw new IOException("No cache directory available");
  }
  if (externalCacheDir == null) {
    cacheDir = internalCacheDir;
  }
  else if (internalCacheDir == null) {
    cacheDir = externalCacheDir;
  } else {
    cacheDir = externalCacheDir.getFreeSpace() > internalCacheDir.getFreeSpace() ?
        externalCacheDir : internalCacheDir;
  }
  return File.createTempFile(TEMP_FILE_PREFIX, getFileExtensionForType(mimeType), cacheDir);
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:26,代码来源:ImageEditingManager.java

示例4: 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

示例5: createWriter

import java.io.File; //导入方法依赖的package包/类
@Nullable
private TransportConnectionWriter createWriter(String filename) {
	if (!running) return null;
	File dir = chooseOutputDirectory();
	if (dir == null || !dir.exists() || !dir.isDirectory()) return null;
	File f = new File(dir, filename);
	try {
		long capacity = dir.getFreeSpace();
		if (capacity < MIN_STREAM_LENGTH) return null;
		OutputStream out = new FileOutputStream(f);
		return new FileTransportWriter(f, out, capacity, this);
	} catch (IOException e) {
		if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
		f.delete();
		return null;
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:18,代码来源:FilePlugin.java

示例6: 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:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:GetXSpace.java

示例7: 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

示例8: 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:variflight,项目名称:feeyo-redisproxy,代码行数:22,代码来源:Util.java

示例9: checkDiskSpace

import java.io.File; //导入方法依赖的package包/类
/**
 * 检查磁盘剩余空间
 */
private void checkDiskSpace(String path, int warningPercent) {
	try {
		nLastCheckDiskTime = System.currentTimeMillis();
		File f = new File(path);
		long n1 = f.getFreeSpace() / (1024 * 1024);
		long n2 = f.getTotalSpace() / (1024 * 1024);
		if (n2 == 0) n2 = 1;
		int nPercent = (int) (100 * n1 / n2);
		logger.info("“" + path + "”分区剩余磁盘空间:" + nPercent + "% [" + n1 + "m/" + n2 + "m]");
		if ("127.0.0.1".equals(mConfigMap.get("LOCAL_IP"))) {
			return;
		}
		if (nPercent < warningPercent) {
			String sContent = mConfigMap.get("LOCAL_IP") + "硬盘“" + path + "”分区可用空间低于"
					+ nPercent + "% [" + n1 + "m/" + n2 + "m],请服务器相关同学处理一下。(本邮件将在5分钟后再次发送)";
			EMail email = new EMail(
					new String[] { "[email protected]" },
					mConfigMap.get("LOCAL_IP") + "硬盘“" + path + "”分区可用空间低于" + nPercent
							+ "%", sContent);
			email.send();
		}
	} catch (Exception ex) {
		logger.error("", ex);
	}
}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:29,代码来源:ProxyBiz.java

示例10: 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:nucypher,项目名称:hadoop-oss,代码行数:10,代码来源:RawLocalFileSystem.java

示例11: 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

示例12: getFreeSpace

import java.io.File; //导入方法依赖的package包/类
@Override
public long getFreeSpace() throws DbException {
	File dir = config.getDatabaseDirectory();
	long maxSize = config.getMaxSize();
	long free = dir.getFreeSpace();
	long used = getDiskSpace(dir);
	long quota = maxSize - used;
	return Math.min(free, quota);
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:10,代码来源:H2Database.java

示例13: check

import java.io.File; //导入方法依赖的package包/类
@Override
public HealthStatus check() {

  File path = new File(this.path);
  long freeBytes = path.getFreeSpace();
  long threshold = thresholdInBytes;

  boolean belowThreshold = freeBytes > threshold;

  return belowThreshold ? reportUp() : reportDown().withAttribute("freebytes", freeBytes);
}
 
开发者ID:thomasdarimont,项目名称:keycloak-health-checks,代码行数:12,代码来源:FilesystemHealthIndicator.java

示例14: detectSdcardIsExist

import java.io.File; //导入方法依赖的package包/类
/**
 * 判断Sdcard是否存在
 *
 * @return
 */
public static boolean detectSdcardIsExist() {
    String extStorageState = Environment.getExternalStorageState();
    File file = Environment.getExternalStorageDirectory();
    if (!Environment.MEDIA_MOUNTED.equals(extStorageState)
            || !file.exists() || !file.canWrite()
            || file.getFreeSpace() <= 0) {
        return false;
    }
    return true;
}
 
开发者ID:Liuzhiyang94,项目名称:ComponentProjectDemo,代码行数:16,代码来源:CommonUtils.java

示例15: 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


注:本文中的java.io.File.getFreeSpace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。