class PicClien {
public static void main(String[] args) throws Exception {
Socket s = new Socket("192.168.0.1", 8007);
FileInputStream fis = new FileInputStream("c:\\1.bmp");
OutputStream out = s.getOutputStream();
byte[] buf = new byte[1024];
int len = 0;
while ((len = fis.read(buf)) != -1) {
out.write(buf, 0, len);
}
System.out.println("发送成功");
fis.close();
s.close();
}
}
import java.io.*;
import java.net.*;
class PicServer {
public static void main(String[] args) throws Exception {
ServerSocket ss = new ServerSocket(8007);
Socket s = ss.accept();
InputStream in = s.getInputStream();
FileOutputStream fos = new FileOutputStream("server.bmp");
byte[] buf = new byte[1024];
int len = 0;
while ((len = in.read(buf)) != -1) {
fos.write(buf, 0, len);
}
fos.close();
s.close();
ss.close();
}