//1.获取服务端网络通道
ServerSocketChannel ssChannel = ServerSocketChannel.open();
//2.为服务端网络通道绑定地址+端口
ssChannel.bind(new InetSocketAddress("127.0.0.1", 8989));
//3.获取客户端连接的通道
SocketChannel sChannel = ssChannel.accept();
//4.获取文件通道
FileChannel fileChannel = FileChannel.open(Paths.get("springmvc学习笔记3.txt"), StandardOpenOption.WRITE,StandardOpenOption.CREATE);
//5.获取缓冲区
ByteBuffer bBuf = ByteBuffer.allocate(1024);
//6.写入本地文件
while(sChannel.read(bBuf)!=-1){
//进入读模式
bBuf.flip();
fileChannel.write(bBuf);
bBuf.clear();
}
fileChannel.close();
sChannel.close();
ssChannel.close();
System.out.println("game over.....");
ServerSocketChannel ssChannel = ServerSocketChannel.open();
//2.为服务端网络通道绑定地址+端口
ssChannel.bind(new InetSocketAddress("127.0.0.1", 8989));
//3.获取客户端连接的通道
SocketChannel sChannel = ssChannel.accept();
//4.获取文件通道
FileChannel fileChannel = FileChannel.open(Paths.get("springmvc学习笔记3.txt"), StandardOpenOption.WRITE,StandardOpenOption.CREATE);
//5.获取缓冲区
ByteBuffer bBuf = ByteBuffer.allocate(1024);
//6.写入本地文件
while(sChannel.read(bBuf)!=-1){
//进入读模式
bBuf.flip();
fileChannel.write(bBuf);
bBuf.clear();
}
fileChannel.close();
sChannel.close();
ssChannel.close();
System.out.println("game over.....");