FileChannel(API详解)
1、两种获取通道的方法 FileChannel.open()的方式 FileChannel channell = FileChannel.open(Paths.get("a.txt","c.txt"), StandardOpenOption.CREATE,StandardOpenOption.WRITE); FileChannel channel2 = FileChannel.open(new File("a.txt").toPath(), StandardOpenOption.CREATE_NEW,StandardOpenOption.WRITE,StandardOpenOption.READ); path获取 Paths.get() new File(“a.txt”).toPath() OpenOption接口的实现类通常由StandardOpenOption枚举进行代替。 public enum StandardOpenOption implements OpenOption { READ, WRITE, APPEND,//累加 TRUNCATE_EXISTING,//如果该文件已存在并且为写入访问而打开,则其长度将被截断为0。如果只为读取访问打开文件,则忽略此选项。 CREATE,//不能单独使用,要与WRITE配套使用,单独使用会报错java.nio.file