欢迎光临散文网 会员登陆 & 注册

TCPFileUploadClient

2023-06-07 10:10 作者:丶摩羯丶  | 我要投稿

public class TCPFileUploadClient{

    public static void main(String[] args) throws IOException {

    Socket socket = new Socket(InetAddress.getLocalHost(), 8888);

    String filePath = "e:\\qie.png";

    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(filePath));

    byte[] bytes = StreamUtils.streamToByteArray(bis);

    BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());

    bos.write(bytes);

    bis.close();

    socket.shutdownoutput();

    InputStream inputStream = socket.getInputStream();

    String s = StreamUtils.streamToString(inputStream);

    System.out.println(s);

    inputStream.close();

    bos.close();

    socket.close


TCPFileUploadClient的评论 (共 条)

分享到微博请遵守国家法律