第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Java通過(guò)套接字發(fā)送和接收文件(字節(jié)[])

Java通過(guò)套接字發(fā)送和接收文件(字節(jié)[])

海綿寶寶撒 2019-10-16 11:09:12
我正在嘗試開(kāi)發(fā)一個(gè)非常簡(jiǎn)單的客戶端/服務(wù)器,其中客戶端將文件轉(zhuǎn)換為字節(jié),將其發(fā)送到服務(wù)器,然后將字節(jié)轉(zhuǎn)換回文件。當(dāng)前,程序僅創(chuàng)建一個(gè)空文件。我不是一名出色的Java開(kāi)發(fā)人員,因此不勝感激。這是接收客戶端發(fā)送的內(nèi)容的服務(wù)器部分。ServerSocket serverSocket = null;    serverSocket = new ServerSocket(4444);    Socket socket = null;    socket = serverSocket.accept();    DataOutputStream out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));    DataInputStream in = new DataInputStream(new BufferedInputStream(socket.getInputStream()));    byte[] bytes = new byte[1024];    in.read(bytes);    System.out.println(bytes);    FileOutputStream fos = new FileOutputStream("C:\\test2.xml");    fos.write(bytes);這是客戶端部分Socket socket = null;    DataOutputStream out = null;    DataInputStream in = null;    String host = "127.0.0.1";         socket = new Socket(host, 4444);    out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));    in = new DataInputStream(new BufferedInputStream(socket.getInputStream()));    File file = new File("C:\\test.xml");    //InputStream is = new FileInputStream(file);    // Get the size of the file    long length = file.length();    if (length > Integer.MAX_VALUE) {        System.out.println("File is too large.");    }    byte[] bytes = new byte[(int) length];    //out.write(bytes);    System.out.println(bytes);    out.close();    in.close();    socket.close();
查看完整描述

3 回答

  • 3 回答
  • 0 關(guān)注
  • 677 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)