Server端 package com.test; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; public class Server implements Runnable { public static final String SERVERIP = "10.0.2.2"; public static final int SERVERPORT = 51706; public void run() { try { System.out.println("S: Connecting..."); ServerSocket serverSocket = new ServerSocket(SERVERPORT); while (true) { //等待接受客户端请求 Socket client = serverSocket.accept(); System.out.println("S: Receiving..."); try { //接受客户端信息 BufferedReader in = new BufferedReader( new InputStreamReader(client.getInputStream())); Socket socket = null; //发送消息 PrintWriter out = new PrintWriter(new BufferedWriter( new OutputStreamWriter(client.getOutputStream())),true); //设置返回信息 out.println("my name is server"); out.flush(); String str = in.readLine(); File file = new File ("C://file//android.txt"); FileOutputStream fops = new FileOutputStream(file); byte [] b = str.getBytes();; for ( int i = 0 ; i < b.length-1; i++ ) { fops.write(b[i]); System.out.println(b.toString()); } System.out.println("S: Received: '" + str + "'"); } catch (Exception e) { System.out.println("S: Error"); e.printStackTrace(); } finally { client.close(); System.out.print