版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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年社区实践
- 2026年护理岗位胜任力培训体系构建指南
- 《GAT 2144-2024法庭科学 涉火案件常见助燃剂及其残留物检验技术导则》专题研究报告
- 2026年中英文保密及隐私保护协议
- 2026标准版离婚协议书(债务分担版)
- 金融风险管理工具与方法(标准版)
- 暗室师春节假期安全告知书
- 健身教练服务与客户管理手册
- (一诊)重庆市九龙坡区区2026届高三学业质量调研抽测(第一次)物理试题
- 2026年榆能集团陕西精益化工有限公司招聘备考题库完整答案详解
- 2026广东省环境科学研究院招聘专业技术人员16人笔试参考题库及答案解析
- 2026年保安员理论考试题库
- (高清版)JGJT 178-2009 补偿收缩混凝土应用技术规程
- 电梯日管控、周排查、月调度内容表格
- QC-提高卫生间防水一次验收合格率
- 江苏省徐州市2022-2023学年高一上学期期末抽测政治试题(原卷版)
- 地基处理施工中的安全风险与防范
- 人教版六年级科学上期末测试题(2份)有答案
- 食品安全全球标准BRCGS第9版内部审核全套记录
评论
0/150
提交评论