Java : FileStore (Storage) con ejemplos
FileStore (Java SE 22 & JDK 22) en Java con ejemplos.
Encontrará muestras de código para la mayoría de los métodos FileStore.
Nota :
- Este artículo puede utilizar software de traducción para su comodidad. Consulte también la versión original en inglés.
Summary
Almacenamiento de archivos. Un FileStore representa un grupo de almacenamiento, un dispositivo, una partición, un volumen, un sistema de archivos concreto u otro medio específico de implementación para almacenar archivos. (Traducción automática)
The code examples on this page are run on Windows.
final var path = Path.of("D:");
System.out.println(path); // D:
final var store = Files.getFileStore(path);
System.out.println(store.type()); // NTFS
// --- PowerShell ---
//PS D:\> Get-PSDrive D
//
//Name Used (GB) Free (GB) Provider Root ...
//---- --------- --------- -------- ---- ...
//D 1597.26 265.63 FileSystem D:\ ...
final var total = store.getTotalSpace();
System.out.printf("%d GB%n", total / (1024 * 1024 * 1024)); // 1862 GB
final var free = store.getUnallocatedSpace();
System.out.printf("%d GB%n", free / (1024 * 1024 * 1024)); // 265 GB
final var used = total - free;
System.out.printf("%d GB%n", used / (1024 * 1024 * 1024)); // 1597 GB
Constructors
FileStore ()
Inicializa una nueva instancia de esta clase. (Traducción automática)
protected. I think it's rare to create a subclass of this class. Therefore, the code example is omitted.
Methods
abstract Object getAttribute (String attribute)
Lee el valor de un atributo de almacén de archivos. (Traducción automática)
final var path = Path.of("D:");
System.out.println(path); // D:
final var store = Files.getFileStore(path);
System.out.println(store.type()); // NTFS
System.out.println(store.getAttribute("volume:isCdrom")); // false
final var path = Path.of("F:");
System.out.println(path); // F:
//PS D:\> Get-Volume F
//
//DriveLetter FriendlyName FileSystemType DriveType ...
//----------- ------------ -------------- --------- ...
//F DVD_ROM Unknown CD-ROM ...
final var store = Files.getFileStore(path);
System.out.println(store.type()); // UDF
System.out.println(store.getAttribute("volume:isCdrom")); // true
long getBlockSize ()
Devuelve la cantidad de bytes por bloque en este almacén de archivos. (Traducción automática)
final var path = Path.of("D:");
System.out.println(path); // D:
final var store = Files.getFileStore(path);
System.out.println(store.getBlockSize()); // 512
abstract <V extends FileStoreAttributeView> V getFileStoreAttributeView (Class<V> type)
Devuelve un FileStoreAttributeView del tipo dado. (Traducción automática)
final var path = Path.of("D:");
System.out.println(path); // D:
final var store = Files.getFileStore(path);
final var view = store.getFileStoreAttributeView(FileStoreAttributeView.class);
System.out.println(view); // null
abstract long getTotalSpace ()
Devuelve el tamaño, en bytes, del almacén de archivos. (Traducción automática)
final var path = Path.of("D:");
System.out.println(path); // D:
final var store = Files.getFileStore(path);
System.out.println(store.type()); // NTFS
// --- PowerShell ---
//PS D:\> Get-PSDrive D
//
//Name Used (GB) Free (GB) Provider Root ...
//---- --------- --------- -------- ---- ...
//D 1597.26 265.63 FileSystem D:\ ...
System.out.println(store.getTotalSpace()); // 2000263573504
System.out.println(store.getUnallocatedSpace()); // 285218787328
System.out.println(store.getUsableSpace()); // 285218787328
final var path = Path.of("F:");
System.out.println(path); // F:
final var store = Files.getFileStore(path);
System.out.println(store.type()); // UDF
// --- PowerShell ---
//PS D:\> Get-PSDrive F
//
//Name Used (GB) Free (GB) Provider Root ...
//---- --------- --------- -------- ---- ...
//F 0.05 0.00 FileSystem F:\ ...
System.out.println(store.getTotalSpace()); // 51329024
System.out.println(store.getUnallocatedSpace()); // 0
System.out.println(store.getUsableSpace()); // 0
abstract long getUnallocatedSpace ()
Devuelve la cantidad de bytes no asignados en el almacén de archivos. (Traducción automática)
final var path = Path.of("D:");
System.out.println(path); // D:
final var store = Files.getFileStore(path);
System.out.println(store.type()); // NTFS
// --- PowerShell ---
//PS D:\> Get-PSDrive D
//
//Name Used (GB) Free (GB) Provider Root ...
//---- --------- --------- -------- ---- ...
//D 1597.26 265.63 FileSystem D:\ ...
System.out.println(store.getTotalSpace()); // 2000263573504
System.out.println(store.getUnallocatedSpace()); // 285218787328
System.out.println(store.getUsableSpace()); // 285218787328
final var path = Path.of("F:");
System.out.println(path); // F:
final var store = Files.getFileStore(path);
System.out.println(store.type()); // UDF
// --- PowerShell ---
//PS D:\> Get-PSDrive F
//
//Name Used (GB) Free (GB) Provider Root ...
//---- --------- --------- -------- ---- ...
//F 0.05 0.00 FileSystem F:\ ...
System.out.println(store.getTotalSpace()); // 51329024
System.out.println(store.getUnallocatedSpace()); // 0
System.out.println(store.getUsableSpace()); // 0
abstract long getUsableSpace ()
Devuelve la cantidad de bytes disponibles para esta máquina virtual Java en el almacén de archivos. (Traducción automática)
final var path = Path.of("D:");
System.out.println(path); // D:
final var store = Files.getFileStore(path);
System.out.println(store.type()); // NTFS
// --- PowerShell ---
//PS D:\> Get-PSDrive D
//
//Name Used (GB) Free (GB) Provider Root ...
//---- --------- --------- -------- ---- ...
//D 1597.26 265.63 FileSystem D:\ ...
System.out.println(store.getTotalSpace()); // 2000263573504
System.out.println(store.getUnallocatedSpace()); // 285218787328
System.out.println(store.getUsableSpace()); // 285218787328
final var path = Path.of("F:");
System.out.println(path); // F:
final var store = Files.getFileStore(path);
System.out.println(store.type()); // UDF
// --- PowerShell ---
//PS D:\> Get-PSDrive F
//
//Name Used (GB) Free (GB) Provider Root ...
//---- --------- --------- -------- ---- ...
//F 0.05 0.00 FileSystem F:\ ...
System.out.println(store.getTotalSpace()); // 51329024
System.out.println(store.getUnallocatedSpace()); // 0
System.out.println(store.getUsableSpace()); // 0
abstract boolean isReadOnly ()
Indica si este almacén de archivos es de solo lectura. (Traducción automática)
final var path = Path.of("D:");
System.out.println(path); // D:
final var store = Files.getFileStore(path);
System.out.println(store.type()); // NTFS
System.out.println(store.isReadOnly()); // false
final var path = Path.of("F:");
System.out.println(path); // F:
//PS D:\> Get-Volume F
//
//DriveLetter FriendlyName FileSystemType DriveType ...
//----------- ------------ -------------- --------- ...
//F DVD_ROM Unknown CD-ROM ...
final var store = Files.getFileStore(path);
System.out.println(store.type()); // UDF
System.out.println(store.isReadOnly()); // true
abstract String name ()
Devuelve el nombre de este almacén de archivos. (Traducción automática)
// --- PowerShell ---
//PS D:\> Get-Volume W
//
//DriveLetter FriendlyName FileSystemType ...
//----------- ------------ -------------- ...
//W Work NTFS ...
final var path = Path.of("W:");
System.out.println(path); // W:
final var store = Files.getFileStore(path);
System.out.println(store.name()); // Work
System.out.println(store.type()); // NTFS
abstract boolean supportsFileAttributeView (Class<? extends FileAttributeView> type)
Indica si este almacén de archivos admite o no los atributos de archivo identificados por la vista de atributos de archivo dada. (Traducción automática)
final var path = Path.of("D:");
System.out.println(path); // D:
final var store = Files.getFileStore(path);
System.out.println(store.type()); // NTFS
final var dos = store.supportsFileAttributeView(DosFileAttributeView.class);
System.out.println(dos); // true
final var posix = store.supportsFileAttributeView(PosixFileAttributeView.class);
System.out.println(posix); // false
abstract boolean supportsFileAttributeView (String name)
Indica si este almacén de archivos admite o no los atributos de archivo identificados por la vista de atributos de archivo dada. (Traducción automática)
final var path = Path.of("D:");
System.out.println(path); // D:
final var store = Files.getFileStore(path);
System.out.println(store.type()); // NTFS
final var dos = store.supportsFileAttributeView("dos");
System.out.println(dos); // true
final var posix = store.supportsFileAttributeView("posix");
System.out.println(posix); // false
abstract String type ()
Devuelve el tipo de este almacén de archivos. (Traducción automática)
final var path = Path.of("D:");
System.out.println(path); // D:
final var store = Files.getFileStore(path);
System.out.println(store.type()); // NTFS
final var path = Path.of("F:");
System.out.println(path); // F:
//PS D:\> Get-Volume F
//
//DriveLetter FriendlyName FileSystemType DriveType ...
//----------- ------------ -------------- --------- ...
//F DVD_ROM Unknown CD-ROM ...
final var store = Files.getFileStore(path);
System.out.println(store.type()); // UDF