国产gaysexchina男同gay,japanrcep老熟妇乱子伦视频,吃奶呻吟打开双腿做受动态图,成人色网站,国产av一区二区三区最新精品

App下載
首頁javaimageJava Graphics - 如何傳輸圖像與Socket流

Java Graphics - 如何傳輸圖像與Socket流

我們想知道如何傳輸圖像與Socket流。
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.Socket;

public class Main {
  public static void main(String[] args) throws Exception {
    Socket socket = new Socket("localhost", 8000);
    File file = new File("C:/Users/abc/Desktop/image.jpg");
    FileInputStream fileInputStream = new FileInputStream(file);

    byte[] fileBytes = new byte[(int) file.length()];
    OutputStream outputStream = socket.getOutputStream();
    int content;
    while ((content = fileInputStream.read(fileBytes)) != -1) {
      outputStream.write(fileBytes, 0, (int) file.length());
    }

    System.out.println("file size is " + fileBytes.length);
    for (byte a : fileBytes) {
      System.out.println(a);
    }
    socket.close();
    fileInputStream.close();
  }
}