Example usage for java.io File getFreeSpace

List of usage examples for java.io File getFreeSpace

Introduction

In this page you can find the example usage for java.io File getFreeSpace.

Prototype

public long getFreeSpace() 

Source Link

Document

Returns the number of unallocated bytes in the partition named by this abstract path name.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    // create new files
    File f = new File("c:/");

    long size = f.getFreeSpace();

    System.out.print(size);/*w ww  .  ja  v  a  2s. c  om*/

}

From source file:Main.java

public static void main(String[] args) {
    File file = new File("C:");
    long totalSpace = file.getTotalSpace();
    System.out.println("Total space on " + file + " = " + totalSpace + "bytes");

    // Check the free space in C:
    long freeSpace = file.getFreeSpace();
    System.out.println("Free space on " + file + " = " + freeSpace + "bytes");
}

From source file:Main.java

public static double getTFlashCardFreeSpace() {
    File dir;
    if (isTFlashCardExists()) {
        dir = new File(T_FLASH_PATH);
        return dir.getFreeSpace();
    }// w  ww . j  a v  a 2 s . c  o  m

    return 0;
}

From source file:Main.java

public static long getFreeSpace(String path) {
    File file = new File(path);
    if (!(file.isDirectory() && file.exists())) {
        file.mkdirs();//from w ww  . jav  a 2  s . com
        if (file.isDirectory()) {
            return file.getFreeSpace();
        } else {
            return 0L;
        }
    } else {
        return file.getFreeSpace();
    }
}

From source file:org.stem.db.FatFileAllocator.java

/**
 * Allocate a directory with files of a given size
 *
 * @param directoryPath/*from ww  w. j  a v a  2s .c  o m*/
 * @param sizeInMB
 * @throws IOException
 */
public static void allocateDirectory(String directoryPath, long sizeInMB) throws IOException {
    File dir = BBUtils.getDirectory(directoryPath);
    allocateDirectory(directoryPath, sizeInMB, dir.getFreeSpace(), false);
}

From source file:org.stem.db.MountPoint.java

public static MountPoint open(String directoryPath, DataTracker dataTracker, boolean init) throws IOException {
    File dir = BBUtils.getDirectory(directoryPath);
    long capacity = dir.getFreeSpace(); // For small fat files

    MountPoint mountPoint = new MountPoint(directoryPath, capacity, dataTracker);
    if (init) {/* ww w. j av  a  2 s  . c om*/
        mountPoint.init();
    }
    return mountPoint;
}

From source file:org.disrupted.rumble.util.FileUtil.java

public static File getWritableAlbumStorageDir() throws IOException {
    if (!isExternalStorageWritable())
        throw new IOException("Storage is not writable");

    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
            RUMBLE_IMAGE_ALBUM_NAME);//from  w ww  .j  a v  a 2s.c  o  m
    file.mkdirs();

    if (file.getFreeSpace() < PushStatus.STATUS_ATTACHED_FILE_MAX_SIZE)
        throw new IOException("not enough space available (" + file.getFreeSpace() + "/"
                + PushStatus.STATUS_ATTACHED_FILE_MAX_SIZE + ")");

    return file;
}

From source file:io.hawkcd.agent.AgentConfiguration.java

private static void configureEnvironmentInfo() {
    File file = new File("/");
    int gb = 1024 * 1024 * 1024;

    environmentInfo.setOsName(System.getProperty("os.name"));
    environmentInfo.setTotalDiskSpaceGBytes(file.getFreeSpace() / gb);
    environmentInfo.setFreeDiskSpaceGBytes(file.getTotalSpace() / gb);
    environmentInfo.setTotalRamMBytes(//  w w w . j  a  v  a 2  s.  c om
            ((OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize()
                    * 1024);
    environmentInfo.setFreeRamMBytes(
            ((OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getFreePhysicalMemorySize()
                    * 1024);
}

From source file:org.alex73.skarynka.scan.process.ProcessCommands.java

public static String call(String s) throws Exception {
    LOG.info("Parse command: " + s);
    StringBuilder out = new StringBuilder();
    Matcher m;/*w  w  w. j  a  v  a  2 s .co  m*/
    if ((m = DO_LS.matcher(s)).matches()) {
        LOG.info("Command ls " + m.group(1));
        List<File> files = new ArrayList<>(FileUtils.listFiles(new File(m.group(1)), null, true));
        Collections.sort(files);
        out.append(s + ":\n");
        for (File f : files) {
            out.append("        " + f.getPath() + "  " + f.length() + "\n");
        }
    } else if ((m = DO_DF.matcher(s)).matches()) {
        LOG.info("Command df " + m.group(1));
        File f = new File(m.group(1));
        long gb = f.getFreeSpace() / 1024 / 1024 / 1024;
        out.append(s + ": " + gb + " gb\n");
    } else if ((m = DO_RM.matcher(s)).matches()) {
        LOG.info("Command rm " + m.group(1));
        File f = new File(m.group(1));
        if (f.isDirectory()) {
            FileUtils.deleteDirectory(f);
        } else {
            f.delete();
        }
    } else if ((m = DO_CP.matcher(s)).matches()) {
        LOG.info("Command cp " + m.group(1) + " " + m.group(2));
        FileUtils.copyFile(new File(m.group(1)), new File(m.group(2)));
    } else if ((m = DO_MVDIR.matcher(s)).matches()) {
        LOG.info("Command mvdir " + m.group(1) + " " + m.group(2));
        FileUtils.moveDirectoryToDirectory(new File(m.group(1)), new File(m.group(2)), true);
    } else {
        throw new Exception("Unknown command: " + s);
    }
    return out.toString();
}

From source file:ch.admin.suis.msghandler.util.FileUtils.java

/**
 * Returns the number of unallocated bytes in the partition named by this path name. If the parameter points to a
 * file, the free disk space from the current parent directory will be calculated.
 *
 * @param file The file/*from ww w . ja  v a  2  s  . c  om*/
 * @return The unallocated bytes
 */
public static long getFreeDiskSpace(File file) {
    if (file.isDirectory()) {
        return file.getFreeSpace();
    } else {
        File parent = file.getParentFile();
        if (parent.exists()) {
            return parent.getFreeSpace();
        } else {
            return -1;
        }
    }
}