学完操作系统回来再写
public class NioTest8 {
public static void main(String[] args) throws IOException {
FileInputStream fileInputStream = new FileInputStream("input2.txt");
FileOutputStream fileOutputStream = new FileOutputStream("output2.txt");
FileChannel fileInputStreamChannel = fileInputStream.getChannel();
FileChannel fileOutputStreamChannel = fileOutputStream.getChannel();
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(512);
while (true){
byteBuffer.clear();
int read = fileInputStreamChannel.read(byteBuffer);
if (-1 == read) break;
byteBuffer.flip();
fileOutputStreamChannel.write(byteBuffer);
}
fileInputStreamChannel.close();
fileOutputStreamChannel.close();
}
}
网友评论