📜  java 通过套接字传输文件 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:27.940000             🧑  作者: Mango

代码示例1
Socket socket =  new Socket() ; //Open a socket with the server
OutputSteam opt = socket.getOutputStream ; // get the outputStream of the socket 
// so we can write in it 
File file = new File(" Path of the file you want to send ") ; 
FileInputStream fis = new FileInputeStream(file) ; 

byte[] data = new byte[ 1024 * 16 ] ;
int count  ; 
while( (count  = fis.read(data))  > 0){
  opt.write(data , 0 , count) ; 
}