亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Java 客戶端向服務(wù)端上傳mp3文件數(shù)據(jù)的實(shí)例代碼

 更新時(shí)間:2018年09月25日 15:46:24   作者:Wnlife  
這篇文章主要介紹了Java 客戶端向服務(wù)端上傳mp3文件數(shù)據(jù)的實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

客戶端:

package cn.itcast.uploadpicture.demo;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;
public class UploadpicClient {
 public static void main(String[] args) throws UnknownHostException, IOException {
 
// 1、建立客戶端的Socket服務(wù)
 Socket s=new Socket("192.168.1.216",10012);
 
// 2、獲取圖片資源
 BufferedInputStream burin=
  new BufferedInputStream(new FileInputStream("F:\\CloudMusic\\羅大佑,黃霑,徐克 - 滄海一聲笑.mp3"));
 
// 3、獲取socket輸出流
 PrintStream pso=new PrintStream(s.getOutputStream(),true);
 
// 4、將數(shù)據(jù)寫入到輸出流
 byte[]buff=new byte[1024];
 int len=-1;
 while((len=burin.read(buff))!=-1) {
  pso.write(buff, 0, len);
 }
 s.shutdownOutput();
 
// 5、獲取服務(wù)端的返回的數(shù)據(jù)
 InputStream is=s.getInputStream();
 byte[]buffin=new byte[1024];
 int lenth=is.read(buffin);
 String str=new String(buffin,0,lenth);
 System.out.println(str);
 
// 6、關(guān)閉流
 s.close();
 burin.close();
 }
}

服務(wù)端:

package cn.itcast.uploadpicture.demo;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
public class UploadpicServer {
 public static void main(String[] args) throws IOException {
 ServerSocket ss=new ServerSocket(10012);
 Socket s=ss.accept();
 
 System.out.println(s.getInetAddress().getHostAddress()+"connnected.......");
 
 BufferedInputStream burin=new BufferedInputStream(s.getInputStream());
 
 File file=new File("serve.mp3");
 if(!file.exists())
  file.mkdirs();
 PrintStream ps=new PrintStream(new FileOutputStream(file),true);
 
 byte[]buff=new byte[1024];
 int len=-1;
 while((len=burin.read(buff))!=-1) {
  ps.write(buff, 0, len);
 }
 
 PrintStream psout=new PrintStream(s.getOutputStream(),true);
 psout.println("上傳成功");
 
 ss.close();
 s.close();
 ps.close();
 }
}

總結(jié)

以上所述是小編給大家介紹的Java 客戶端向服務(wù)端上傳mp3文件數(shù)據(jù)的實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論