Java IO & NIO - Files.getFileStore() Examples

Code Snippets Java IO & NIO Java 


Class:

java.nio.file.Files

java.lang.Objectjava.lang.Objectjava.nio.file.Filesjava.nio.file.FilesLogicBig

Method:

public static FileStore getFileStore(Path path)
                              throws IOException

Returns the FileStore. A FileStore represents file store details where the file is located.

Parameters:
path - the path to the file
Returns:
the file store where the file is stored


Examples


package com.logicbig.example.files;

import java.io.IOException;
import java.nio.file.FileStore;
import java.nio.file.Files;
import java.nio.file.Path;

public class GetFileStoreExample {

public static void main(String... args) throws IOException {
Path tempFile = Files.createTempFile("test-file", ".txt");
FileStore fileStore = Files.getFileStore(tempFile);
System.out.println("total space: " + fileStore.getTotalSpace());
System.out.println("unallocated space: " + fileStore.getUnallocatedSpace());
System.out.println("usable space: " + fileStore.getUsableSpace());
System.out.println("store type: " + fileStore.type());
}
}

Output

total space: 142541602816
unallocated space: 22585438208
usable space: 22585438208
store type: NTFS




See Also