客户端
public class Client01 {
public static void main(String[] args) throws IOException {
//创建客户端对象Socket,并在参数里,指定主机地址和端口
Socket socket = new Socket("127.0.0.1", 20000);
//创建本地 字节缓冲输入流读取本地文件内存 准备进行网络传输
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\\Users\\86185\\Desktop\\十秒实现存款十个亿的方法.wmv"));
//将客户端对象转换成网络输出流
OutputStream os = socket.getOutputStream();
//将本地输入流 转换成网络输出缓冲流 写到服务器
// 先从硬盘写到内存,再从内存写到网络
BufferedOutputStream bos = new BufferedOutputStream(os);
/* //写个字符串数据,封装成字节数组
byte[] bytes = "洛天依演唱会抢票了".getBytes();
os.write(bytes);
//用客户端对象结束网络输出流,shutdownOutput只会关闭网络流。*/
//y用本地流从硬盘中读取文件到内存,在用网络流从内存写到网络
int b;
while ((b=bis.read())!=-1){
bos.write((char)b);
}
bos.flush();//刷新网络流
socket.shutdownOutput();
//创建缓冲字符输入流