客户端:
- package com.kxg_09;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.net.Socket;
- /*
- * 客户端文本文件,服务器输出在控制台
- */
- public class ClientDemo {
- public static void main(String[] args) throws IOException {
- // 创建客户端Socket对象
- Socket s = new Socket("10.164.22.254", 48264);
- // 封装数据源
- BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
- "a.txt"));
- // 封装通道中的流
- BufferedOutputStream bos = new BufferedOutputStream(s.getOutputStream());
- // 读取数据源
- byte[] bys = new byte[1024];
- int len = 0;
- while ((len = bis.read(bys)) != -1) {
- // 读取内容写入到通道流中
- bos.write(bys, 0, len);
- }
- // 释放资源
- bis.close();
- bos.close();
- }
- }
复制代码
|
|