![java文件上傳程序_第1頁](http://file4.renrendoc.com/view/6954d87191d4d49ae0d28ce501120347/6954d87191d4d49ae0d28ce5011203471.gif)
![java文件上傳程序_第2頁](http://file4.renrendoc.com/view/6954d87191d4d49ae0d28ce501120347/6954d87191d4d49ae0d28ce5011203472.gif)
![java文件上傳程序_第3頁](http://file4.renrendoc.com/view/6954d87191d4d49ae0d28ce501120347/6954d87191d4d49ae0d28ce5011203473.gif)
![java文件上傳程序_第4頁](http://file4.renrendoc.com/view/6954d87191d4d49ae0d28ce501120347/6954d87191d4d49ae0d28ce5011203474.gif)
![java文件上傳程序_第5頁](http://file4.renrendoc.com/view/6954d87191d4d49ae0d28ce501120347/6954d87191d4d49ae0d28ce5011203475.gif)
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
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壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030全球PCA輸液泵行業(yè)調研及趨勢分析報告
- 2025年全球及中國結構型包裝用蜂窩行業(yè)頭部企業(yè)市場占有率及排名調研報告
- 2025-2030全球自主最后一英里送貨機器人行業(yè)調研及趨勢分析報告
- 2025年全球及中國可見光超透鏡行業(yè)頭部企業(yè)市場占有率及排名調研報告
- 2025-2030全球鈑金沖焊型液力變矩器行業(yè)調研及趨勢分析報告
- 2025-2030全球教育行業(yè)CRM軟件行業(yè)調研及趨勢分析報告
- 2025-2030全球艾氏劑行業(yè)調研及趨勢分析報告
- 2025-2030全球卡車液力變矩器行業(yè)調研及趨勢分析報告
- 2025年全球及中國鈷鐵合金軟磁材料行業(yè)頭部企業(yè)市場占有率及排名調研報告
- 2025-2030全球高速RDF制粒機行業(yè)調研及趨勢分析報告
- 小學六年級數學上冊《簡便計算》練習題(310題-附答案)
- 地理標志培訓課件
- 2023行政主管年終工作報告五篇
- 2024年中國養(yǎng)老產業(yè)商學研究報告-銀發(fā)經濟專題
- 培訓如何上好一堂課
- 高教版2023年中職教科書《語文》(基礎模塊)下冊教案全冊
- 2024醫(yī)療銷售年度計劃
- 稅務局個人所得稅綜合所得匯算清繳
- 人教版語文1-6年級古詩詞
- 上學期高二期末語文試卷(含答案)
- 人教版英語七年級上冊閱讀理解專項訓練16篇(含答案)
評論
0/150
提交評論