每句话都有注释,应该是没有问题可以看懂的
服务器端
/*
* 文件上传多线程版本, 服务器端
*/
public class TCPServer {
public static void main(String[] args) throws IOException {
//1,创建服务器,等待客户端连接
ServerSocket serverSocket = new ServerSocket(6666);
//实现多个客户端连接服务器的操作
while(true){
final Socket clientSocket = serverSocket.accept();
//启动线程,完成与当前客户端的数据交互过程
new Thread(){
public void run() {
try{
//显示哪个客户端Socket连接上了服务器
InetAddress ipObject = clientSocket.getInetAddress();//得到IP地址对象
String ip = ipObject.getHostAddress(); //得到IP地址字符串
System.out.println("小样,抓到你了,连接我!!" + "IP:" + ip);
//7,获取Socket的输入流
InputStream in = clientSocket.getInputStream();
//8,创建目的地的字节输出流 D:\\upload\\192.168.74.58(1).jpg
BufferedOutputStream fileOut = new BufferedOutputStream(new F