public class clentDemo {
public static void main(String[] args) throws Exception {
// 创建客户端套接字对象
Socket s = new Socket("127.0.0.1", 8989);
// 获取输出流
OutputStream ou = s.getOutputStream();
// 创建字节输入读取本地文件
FileInputStream in = new FileInputStream("D:\\....\\.bmp");
// 字节缓存数组
byte[] buf = new byte[1024];
int len = 0;
// 循环把文件保存到服务器
if ((len = in.read(buf)) != -1) {
ou.write(buf, 0, len);
}
s.shutdownOutput();
in.close();
System.out.println("文件已发送到服务器了");
// 接受服务器反回的信息
// 获取输入流
InputStream sin = s.getInputStream();
byte[] buf1 = new byte[1024];
int len1 = 0;
len1 = sin.read(buf1);
System.out.println(new String(buf1, 0, len1));
s.close();
}
}
07-30