public void testWindows() throws Exception { // ==== Testing Windows filesystem === // two options to write - WRITE, WRITE + APPEND. Simple writes just rewrite current values SeekableByteChannel s = Files.newByteChannel( Paths.get("test.txt"), StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.CREATE); // , StandardOpenOption.APPEND); ByteBuffer bb = ByteBuffer.wrap("12345".getBytes()); s.truncate(0); // clear file s.position(0); // start position s.write(bb); bb.position(2); s.write(bb); // s.position(0); byte[] bbrb = new byte[(int) s.size()]; s.read(ByteBuffer.wrap(bbrb)); System.out.println(new String(bbrb)); // should be 12345345 s.close(); }