版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
importjava.io.*;import.*;importjava.util.*;publicclassServer{ publicstaticvoidmain(Stringargs[]){ try { ServerSocketserver=newServerSocket(8888); System.out.println("服务器在监听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("发送文献"); 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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 成人非心胸手术围手术期机械通气专家共识解读总结2026
- 上海崇明区2025-2026学年高三下学期二模语文试卷答案
- Unit 5 Nature's Temper Section A 知识清单 新教材人教版八年级英语下册
- 2026年java高级考试试题及答案
- 正态分布赋能映射系统安全:理论、机制与实践
- 正则化与稀疏扫描协同:光声成像重建的精度提升策略
- 欧盟两性平等政策对女性劳动力参与率的多维影响:基于成员国比较视角
- 欣美电器公司精细化成本管理的应用与成效研究
- 2026年国际贸易法律实务考试及答案
- 橄榄星室木虱生物防治的探索与实践:理论、应用与展望
- (2025年)医师定期考核题库附答案
- GB/T 3159-2026液压式万能试验机
- 2026年建安杯信息通信建设行业安全竞赛重点题库(新版)
- 12《古诗三首》课件-2025-2026学年统编版语文三年级下册
- 短剧网络播出要求与规范手册
- 江苏苏锡常镇四市2026届高三下学期教学情况调研(一)数学试题(含答案)
- 高顿教育内部考核制度
- 2026年扎兰屯职业学院单招职业技能考试题库及答案解析
- 2026年山西工程职业学院单招职业技能考试题库及答案解析
- 慈善总会考核制度
- 萤石矿采选项目社会稳定风险评估报告
评论
0/150
提交评论