package com.nio.bufferDemo;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
/**
* @ClassName
* @Description
* @Author qiangsw
* @date 2021/3/12 22:33
* @Version 1.0
* 参考张龙老师视频学习
*/
public class FileDemo {
/**
* buteBuffer 放入数据后读取 一定需要翻转
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// writeFile();
// readFile();
readAndWrite();
}
/**
* 写文件
*
* @throws Exception
*/
public static void writeFile() throws Exception {
FileOutputStream outputStream = new FileOutputStream("out.txt");
FileChannel channel = outputStream.getChannel();
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(50);
byteBuffer.put("hello,nio".getBytes());
byteBuff
Java-NIO之Buffer(二)文件读取
于 2021-03-13 12:12:37 首次发布