用SeekableByteChannel写入文件
/** from nowjava.com**/ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.SeekableByteChannel; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.EnumSet; public class Main { public static void main(String[] args) { Path path = Paths.get("C:/folder1/folder0/folder8", "story.txt"); try (SeekableByteChannel seekableByteChannel = Files.newByteChannel(path, EnumSet.of(StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING))) { ByteBuffer buffer = ByteBuffer.wrap("this is a test".getBytes()); int write = seekableByteChannel.write(buffer); /* from n o w j a v a