客戶端:
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ù)寫(xiě)入到輸出流 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(); } }
本文標(biāo)題:Java客戶端向服務(wù)端上傳mp3文件數(shù)據(jù)的實(shí)例代碼-創(chuàng)新互聯(lián)
網(wǎng)址分享:http://jinyejixie.com/article8/jijip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、建站公司、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站排名、動(dòng)態(tài)網(wǎng)站、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容