List of usage examples for java.nio.file FileStore getUsableSpace
public abstract long getUsableSpace() throws IOException;
From source file:Main.java
public static void main(String[] args) throws IOException { FileSystem fileSystem = FileSystems.getDefault(); for (FileStore store : fileSystem.getFileStores()) { System.out.println(store.getUsableSpace()); }/*from w w w. j ava 2 s . c o m*/ }
From source file:Test.java
public static void main(String[] args) throws Exception { FileSystem fileSystem = FileSystems.getDefault(); for (FileStore fileStore : fileSystem.getFileStores()) { long totalSpace = fileStore.getTotalSpace() / kiloByte; long usedSpace = (fileStore.getTotalSpace() - fileStore.getUnallocatedSpace()) / kiloByte; long usableSpace = fileStore.getUsableSpace() / kiloByte; String name = fileStore.name(); String type = fileStore.type(); boolean readOnly = fileStore.isReadOnly(); }/*from w w w . j a va2 s.com*/ }
From source file:Main.java
public static void printDetails(FileStore store) { try {/*from w ww. ja va 2 s . c o m*/ String desc = store.toString(); String type = store.type(); long totalSpace = store.getTotalSpace(); long unallocatedSpace = store.getUnallocatedSpace(); long availableSpace = store.getUsableSpace(); System.out.println(desc + ", Total: " + totalSpace + ", Unallocated: " + unallocatedSpace + ", Available: " + availableSpace); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.commander4j.util.JUtility.java
public static String diskFree() { String result = ""; long free = 0; File f = new File(System.getProperty("user.dir")); String root = ""; while (f.getParent() != null) { root = f.getParent();/* w w w. j a va2 s .co m*/ f = new File(root); } try { URI rootURI = new URI("file:///"); Path rootPath = Paths.get(rootURI); Path dirPath = rootPath.resolve(root); FileStore dirFileStore = Files.getFileStore(dirPath); free = dirFileStore.getUsableSpace() / 1048576; result = String.valueOf(free) + " mb on " + root; } catch (Exception e) { result = "Error trying to determine free disk space " + e.getLocalizedMessage(); } return result; }
From source file:com.ethercamp.harmony.service.BlockchainInfoService.java
/** * Get free space of disk where project located. * Verified on multi disk Windows./* w ww .j ava 2 s. c o m*/ * Not tested against sym links */ private long getFreeDiskSpace() { final File currentDir = new File("."); for (Path root : FileSystems.getDefault().getRootDirectories()) { // log.debug(root.toAbsolutePath() + " vs current " + currentDir.getAbsolutePath()); try { final FileStore store = Files.getFileStore(root); final boolean isCurrentDirBelongsToRoot = Paths.get(currentDir.getAbsolutePath()) .startsWith(root.toAbsolutePath()); if (isCurrentDirBelongsToRoot) { final long usableSpace = store.getUsableSpace(); // log.debug("Disk available:" + readableFileSize(usableSpace) // + ", total:" + readableFileSize(store.getTotalSpace())); return usableSpace; } } catch (IOException e) { log.error("Problem querying space: " + e.toString()); } } return 0; }
From source file:fr.ortolang.diffusion.store.binary.BinaryStoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) public List<BinaryStoreContent> systemBrowse(String name, String prefix) throws BinaryStoreServiceException { if (name == null || name.length() == 0) { List<BinaryStoreContent> vinfos = new ArrayList<BinaryStoreContent>(); List<String> vnames = new ArrayList<String>(); vnames.addAll(BinaryStoreVolumeMapper.listVolumes()); vnames.add(WORK);/* w w w . j a v a 2s . co m*/ for (String vname : vnames) { try { BinaryStoreContent volume = new BinaryStoreContent(); Path vpath = Paths.get(base.toString(), vname); FileStore vstore = Files.getFileStore(vpath); volume.setPath(vname); volume.setType(Type.VOLUME); volume.setFsName(vstore.name()); volume.setFsType(vstore.type()); volume.setFsTotalSize(vstore.getTotalSpace()); volume.setFsFreeSize(vstore.getUsableSpace()); volume.setSize(Files.size(vpath)); volume.setLastModificationDate(Files.getLastModifiedTime(vpath).toMillis()); vinfos.add(volume); } catch (IOException e) { LOGGER.log(Level.WARNING, "Unable to retrieve binary store volume information for volume: " + vname); } } return vinfos; } else { try { if (prefix == null) { prefix = ""; } Path vpath = Paths.get(base.toString(), name, prefix); if (!Files.exists(vpath)) { throw new BinaryStoreServiceException( "volume name does not point to an existing file or a directory"); } return Files.list(vpath).map(this::pathToContent).collect(Collectors.toList()); } catch (IOException e) { throw new BinaryStoreServiceException(e); } } }
From source file:de.blizzy.backup.backup.BackupRun.java
private void checkDiskSpaceAndRemoveOldBackups() { try {//from ww w .j ava 2s. co m FileStore store = Files.getFileStore(new File(settings.getOutputFolder()).toPath()); long total = store.getTotalSpace(); if (total > 0) { for (;;) { long available = store.getUsableSpace(); if (available <= 0) { break; } double avail = available * 100d / total; if (avail >= (100d - settings.getMaxDiskFillRate())) { break; } if (!removeOldestBackup()) { break; } removeUnusedFiles(); } } } catch (IOException e) { // ignore } catch (DataAccessException e) { BackupPlugin.getDefault().logError("error removing oldest backup", e); //$NON-NLS-1$ fireBackupErrorOccurred(e, BackupErrorEvent.Severity.WARNING); } }