public static void nioTest() throws IOException {
File file = new File("D://3.txt");
FileChannel fileChannel = new FileOutputStream(file).getChannel();
fileChannel.close();
}
我这边初学有点小疑问,就是只要执行了上面的代码,“3.txt” 的内容就自动清空了,我不理解的点就是 为什么我还没有向管道中存放数据,就已经把文件中的内容给抵消掉了,我这边看了一下,只要FileChannel这个对象创建出来了,文件自己就空了。希望有懂这方面的朋友可以解答一下,谢谢了。