Tag: 磁盘

如何在Java 7中可移植地获取文件存储的块大小?

我查看了java.nio.file.attribute.Attributes和java.nio.file.FileStore ,但找不到发现磁盘文件块大小的方法。

使用Java NIO直接访问Windows磁盘

我正在使用一个使用Java NIO的库,以便直接将文件映射到内存,但是我无法直接读取磁盘。 我可以使用带有UNC的FileInputStream直接读取磁盘,例如 File disk = new File(“\\\\.\\PhysicalDrive0\\”); try (FileInputStream fis = new FileInputStream(disk); BufferedInputStream bis = new BufferedInputStream(fis)) { byte[] somebytes = new byte[10]; bis.read(somebytes); } catch (Exception ex) { System.out.println(“Oh bother”); } 但是,我无法将其扩展到NIO: File disk = new File(“\\\\.\\PhysicalDrive0\\”); Path path = disk.toPath(); try (FileChannel fc = FileChannel.open(path, StandardOpenOption.READ)){ System.out.println(“No exceptions! Yay!”); } catch […]