Tag: memory mapping

如何在Java中存储映射(mmap)linux块设备(例如/ dev / sdb)?

我可以使用java.nio读取/编写带有Java的linux块设备。 以下代码有效: Path fp = FileSystems.getDefault().getPath(“/dev”, “sdb”); FileChannel fc = null; try { fc = FileChannel.open(fp, EnumSet.of(StandardOpenOption.READ, StandardOpenOption.WRITE)); } catch (Exception e) { System.out.println(“Error opening file: ” + e.getMessage()); } ByteBuffer buf = ByteBuffer.allocate(50); try { if(fc != null) fc.write(buf); } catch (Exception e) { System.out.println(“Error writing to file: ” + e.getMessage()); } 但是,内存映射不起作用。 以下代码失败 […]