使用FileChannel写入文本文件
import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.file.Path;/*n o w j a v a . c o m*/ 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/email", "test.txt"); ByteBuffer buffer = ByteBuffer.wrap("this is a test".getBytes()); try (FileChannel fileChannel = (FileChannel.open(path, EnumSet.of(StandardOpenOption.READ, StandardOpenOption.WRITE)))) { /* n o w j a v a . c