java.nio.file.FileStore Class in Java Last Updated : 03 Oct, 2022 Comments Improve Suggest changes Like Article Like Report Java.nio.file is a package in java that consists of the FileStore class. FileStore class is a class that provides methods for the purpose of performing some operations on file store. FileStore is a class that extends Object from java.lang package. And few methods the FileStore class can inherit from java.lang.Object package is clone(), equals(), finalize(), getClass(), hashCode(), notify(), notifyAll(), toString(), wait().getFileStore() is a method provided by FileStore class which is invoked to know where the file got stored in general it tells the location of the file where it got stored in the CD drive.And FileStore also supports few or more classes like FileStoreAttributeView which provides a read-only or up view of a set of file store attributes. Syntax: Class Declaration public abstract class FileStore extends Object { abstract CheckResult( ); // Here an abstract method which // don't have usually a method definition part. } Note: Whenever you create an object for abstract class and tried to call it while compile time the compiler throws an error saying "the method is in-complete” this happens because Abstract is known as incomplete which means you cannot create an object for methods like this. Constructors of FileStore Class is as follows: ConstructorDescriptionFileStore()This constructor Initializes a new instance of this class. Methods of FileStore Class are as follows: MethodsDescription getAttribute(String attribute)This method reads the value of a file store attribute.getFileStoreAttributeView(Class<V> type)This method returns a FileStoreAttributeView of the given type. getTotalSpace()This method returns the size, in bytes, of the file store.getUnallocatedSpace()This method returns the number of unallocated bytes in the file store. getUsableSpace()This method returns the number of bytes available to this Java virtual machine on the file store.isReadOnly()This method tells whether this file store is read-only. name()This method returns the name of this file store.supportsFileAttributeView(Class<? extends FileAttributeView> type)This method tells whether this file store supports the file attributes identified by the given file attribute view. supportsFileAttributeView(String name)This method tells whether this file store supports the file attributes identified by the given file attribute view. type()This method returns the type of this file store. Example 1: Java // Java Program to demonstrate FileStore Class // with its methods // Importing required libraries import java.nio.file.FileStore; import java.nio.file.FileSystem; import java.nio.file.FileSystems; // Main class public class GFG { // Declaring and initializing variable static long Bytes = 1000; // Main driver method public static void main(String[] args) throws Exception { // Creating an object of FileSystem class FileSystem fileSystem = FileSystems.getDefault(); for (FileStore fileStore : fileSystem.getFileStores()) { // Here we use Bytes to // get the usable space in terms of bytes. // Here getUsableSpace method is used to // know the free space in the drive. // then it written back the value into // usableSpace variable long usableSpace = fileStore.getUsableSpace() / Bytes; // Here we use Bytes to // get the used space in terms of bytes. // Here we get the usedspace value by // subtracting the methods given below. long usedSpace = (fileStore.getTotalSpace() - fileStore .getUnallocatedSpace()) / Bytes; // Readonly writes true or false based on // the mode the we file open. boolean readOnly = fileStore.isReadOnly(); // Print and display the information // that the methods are allocated with System.out.println( "All information on the FileStore"); // Print and display used and unused space System.out.println("Used Space : " + usedSpace); System.out.println("Un-Used Space : " + usableSpace); // Print boolean true false whether it is read // only System.out.println("Is this read only : " + readOnly); } } } Output: Example 2: Java // Java Program to demonstrate FileStore Class // with its methods // Importing required libraries import java.nio.file.FileStore; import java.nio.file.FileSystem; import java.nio.file.FileSystems; // Main class // FileStoreExample public class GFG { // Main driver method public static void main(String[] args) throws Exception { // Creating an object of FileSystem class FileSystem fileSystem = FileSystems.getDefault(); // Iterating for file storage using for each loop for (FileStore fileStore : fileSystem.getFileStores()) { // Here filestore() is used to know the // folder/drive name where the actual file is // getting stored String fileStoreName = fileStore.name(); // This method returns the fileStore type String fileStoreType = fileStore.type(); // Print and display commands // 1. information of file System.out.println( "All information on the FileStores\n\n"); // 2. Name of a file stored System.out.println("File Store Name : " + fileStoreName); // 3. Type of file stored System.out.println("File Store Type : " + fileStoreType); } } } Output Comment More infoAdvertise with us Next Article java.nio.file.FileStore Class in Java P pranaythanneru Follow Improve Article Tags : Java Java-NIO package Java-Classes Java-FileStore Practice Tags : Java Similar Reads java.nio.file.FileSystem class in java java.nio.file.FileSystem class provides an interface to a file system. The file system acts as a factory for creating different objects like Path, PathMatcher, UserPrincipalLookupService, and WatchService. This object help to access the files and other objects in the file system. Syntax: Class decla 4 min read java.nio.file.spi.FileTypeDetector Class in Java java.nio.file.spi.FileTypeDetector Class extends java.lang.Object Class. FileTypeDetector Class contain method to know about the content type of given file. Class declaration: public abstract class FileTypeDetector extends ObjectConstructor: ConstructorDescriptionprotected FileTypeDetector()It is us 2 min read java.nio.file.attribute.FileTime Class in Java The java.nio.file.attribute.FileTime class is used to get a value representing this file's timestamp i.e, the time when this file was last modified, accessed, or created. Class Declaration: public final class FileTime extends Object implements Comparable<FileTime>Methods: MethodDescriptioncomp 2 min read java.nio.FloatBuffer Class in Java A Buffer object can be termed as a container for a fixed amount of data. The buffer acts as a storing box, or temporary staging area, where data can be stored and later retrieved according to the usage. Java Buffer classes are the foundation or base upon which java.nio is built. Float buffers are cr 4 min read java.nio.file.Paths Class in Java java.nio.file.Paths class contains static methods for converting path string or URI into Path. Class declaration : public final class Paths extends ObjectMethods: MethodDescriptionget(String first, String... more) This method converts a path string, or a sequence of strings that when joined form a p 2 min read java.nio.file.LinkPermission Class in Java The java.nio.file.LinkPermission class handles permissions for link creation operations. The permission allowed by these class are as follows: Permission name What permission allows Risk of granting this permission hard This permission allows adding an existing file to a directory. This operation is 3 min read Files getFileStore() method in Java with Examples getFileStore() method of java.nio.file.Files help us to return the FileStore object which represents the file store where a file is located. Once you get a reference to the FileStore you can apply filestore type of operation to get information of filestore. Syntax: public static FileStore getFileSto 2 min read Java FileInputStream Class FileInputStream class in Java is useful for reading data from a file in the form of a Java sequence of bytes. FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader.Example: FileInputStream class to read data from fi 4 min read java.nio.Buffer Class in Java The Buffer class provides a buffer or a container for data chunks of specific primitive types. A finite sequence of elements is stored linearly in a buffer. Important properties of a buffer that make it convenient to perform read and write operations in the data are: Capacity: This property determin 4 min read java.nio.file.SimpleFileVisitor Class in Java The java.nio.file.SimpleFileVisitor Class is used to visit all the files in a directory and to re-throw I/O exceptions whenever an I/O error occurs. Class declaration : public class SimpleFileVisitor<T> extends Object implements FileVisitor<T>Constructor: protected SimpleFileVIsitor(): C 3 min read Like