TCPFileUploadServer
public class TCPFileUploadServer{
? ? public static void main(String[] args) throws IOException{
? ? ServerSocket serverSocket = new ServerSocket(8888);
? ? System.out.println("服務(wù)端在8888端口監(jiān)聽....");
? ? Socket socket = serverSocker.accept();
? ? BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
? ? byte[] bytes = StreamUtils.streamToByteArray(bis);
? ? String destFilePath = "src\\qie2.png";
? ? BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destFilePath));
? ? bos.write(bytes);
? ? bos.close();
? ? BufferedWriter writernew BufferedWriter(new OutputStreamWriter(socket.getOutputSream()));
? ? writer.write("收到圖片");
? ? writer.flush();
? ? socket.shutdownOutput();
? ? writer.close();
? ? bis.close();
? ? socket.close();
? ? serverSocket.close();