TCP/IP传输之后文件变大,格式不正确打不开

客户端发送文件给服务端,服务端将文件保存在本地。
进行图片的传输,传输成功后,文件比原来打了好多倍,本来只有1.13MB,传输成功写入到硬盘的时候变成了143.57MB?这是什么原因呢。


public class TCPTest2 {
    @Test
    public void client() throws Exception{

        // 1.
        InetAddress inet1 = InetAddress.getByName("127.0.0.1");
        Socket soc = new Socket(inet1, 9966);
        // 2.
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("mm.jpg"));
        // 3.
        OutputStream os = soc.getOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(os);
        // 4.
        byte[] buffer = new byte[1024];
        int len;
        while ((len = bis.read()) != -1) {
            bos.write(buffer, 0, len);
        }
        // 5.
        bos.close();
        os.close();
        bis.close();
        soc.close();
    }

    @Test
    public void server() throws Exception{
        // 1.
        ServerSocket ss = new ServerSocket(9966);
        // 2.
        Socket soc = ss.accept();
        // 3.
        InputStream is = soc.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);
        // 4.
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("mm1.jpg"));
        // 5.
        byte[] buffer = new byte[1024];
        int len;
        while ((len = bis.read(buffer)) != -1) {
            bos.write(buffer, 0, len);
        }
        // 6.
        bos.close();
        bis.close();
        is.close();
        soc.close();
        ss.close();
    }

}

img
打开之后是这样的

img

用字符流实现读写。
https://blog.csdn.net/Mrchongyang/article/details/83384322?utm_source=app&app_version=4.11.0

17行写错了

while ((len = bis.read(buffer)) != -1) {