版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
importjava.io.*;import.*;importjava.util.*;publicclassServer{ publicstaticvoidmain(Stringargs[]){ try { ServerSocketserver=newServerSocket(8888); System.out.println("服務器在監(jiān)聽8888端口..."); while(true) { Socketsocket=server.accept(); newReceFile(socket).start(); } } catch(Exceptione) { e.printStackTrace(); } }}//服務器接受文獻線程classReceFileextendsThread{ privateSocketsocket; publicReceFile(Socketsocket){ this.socket=socket; } publicvoidrun(){ InputStreamis=null; OutputStreamos=null; DataInputStreamdis=null; InetAddressaddress=null; Stringip=""; try { //獲得輸入流 is=socket.getInputStream(); //獲取連接此輸入流的地址 address=socket.getInetAddress(); //返回ip ip=address.getHostAddress(); dis=newDataInputStream(is); //讀取上傳過過來的文獻名 StringfileName=dis.readUTF(); System.out.println("服務器接受到自"+ip+"的"+fileName+"文獻"); //將接受到的文獻保留到指定的目錄 os=newFileOutputStream("File/"+fileName); intlen=0; byte[]b=newbyte[1024]; while(true) { len=is.read(b); if(len==-1) { break; } os.write(b,0,len); os.flush(); } } catch(Exceptione) { e.printStackTrace(); } finally{ try { if(is!=null) { is.close(); } if(dis!=null) { dis.close(); } if(os!=null) { os.close(); } } catch(Exceptionex) { ex.printStackTrace(); } } }}importjava.io.*;import.*;importjava.util.*;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importorg.roy.*;publicclassClientextendsJFrameimplementsActionListener{ privateJButtonselbutton,upbutton; privateJPaneljp; privateStringpath; publicClient(){ super("文獻上傳"); this.setSize(250,250); this.setLocation(300,400); init(); this.setVisible(true); this.setDefaultCloseOperation(EXIT_ON_CLOSE); } publicvoidinit(){ selbutton=newJButton("選擇文獻"); upbutton=newJButton("上傳"); jp=newJPanel(); selbutton.addActionListener(this); upbutton.addActionListener(this); jp.add(selbutton); jp.add(upbutton); this.add(jp); } publicvoidactionPerformed(ActionEvente){ if(e.getSource()==selbutton){ //使用包途徑 path=IOUtil.fetch().getPathFile().getAbsolutePath(); } if(e.getSource()==upbutton){ System.out.println("發(fā)送文獻"); if(path!=null&&!path.equals("")){ //在后臺運行的 newSendFile(path).start();//啟動一種線程 }else{ System.out.println("請選擇文獻.."); } } } publicstaticvoidmain(Stringargs[]){ newClient(); }}classSendFileextendsThread{ privateSocketsocket; privateStringpath; publicSendFile(Stringpath){ this.path=path; } publicvoidrun(){ InputStreamis=null; OutputStreamos=null; Filefile=null; Propertiespro=null; try { file=newFile(path); if(file.exists()) { is=newFileInputStream(file); InputStreamispro=newFileInputStream("perties"); pro=newProperties(); //從輸入流中讀取屬性列表(鍵和元素對)。 pro.load(ispro); socket=newSocket(pro.getProperty("ip"),Integer.parseInt(pro.getProperty("port"))); os=socket.getOutputStream(); StringfileName=file.getName(); DataOutputStreamdos=newDataOutputStream(os); dos.writeUTF(fileName); intlen=0; byte[]b=newbyte[1024]; while(true) { len=is.read(b); if(len==-1) { break; } os.write(b,0,len); os.flush(); } } } catch(Exceptione) { e.printStackTrace(); } finally{ try
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年外科培訓考試題目及答案
- 高校實驗教學安全管理操作流程
- 中小學師資培訓全流程管理方案
- 電氣設備維護保養(yǎng)培訓手冊
- 2026年線下員工培訓協(xié)議
- 2026黑龍江哈爾濱啟航勞務派遣有限公司派遣到哈工大儀器學院導航儀器研究所招聘備考題庫及答案詳解(考點梳理)
- 2026福建廣電網(wǎng)絡集團龍海分公司招聘2人備考題庫參考答案詳解
- 2026西藏那曲市嘉黎縣委政法委補招專職網(wǎng)格員1人備考題庫及答案詳解1套
- 2026湖北荊州市長江大學城市建設學院人才招聘備考題庫含答案詳解
- 企業(yè)跨文化交流培訓課程設計
- 2026年山東省威海市單招職業(yè)傾向性測試題庫附答案解析
- 2026新疆伊犁州新源縣總工會面向社會招聘工會社會工作者3人考試備考試題及答案解析
- 積極思想培訓
- 2026春譯林8下單詞表【Unit1-8】(可編輯版)
- 2026年《必背60題》抖音本地生活BD經理高頻面試題包含詳細解答
- 駱駝祥子劇本殺課件
- 電影短片拍攝實踐課件
- 2025首都文化科技集團有限公司招聘9人考試筆試備考題庫及答案解析
- 《經典常談》導讀課件教學
- 農業(yè)科技合作協(xié)議2025
- 護理文書書寫規(guī)范與法律風險規(guī)避
評論
0/150
提交評論