版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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上海交通大学医学院招聘91人备考题库及答案详解(各地真题)
- 用户界面设计新趋势解析
- 盛达冷干机培训课件
- 2026陕西环保产业集团招聘试题及答案
- 2026山东港口集团招聘试题及答案
- 2026广东佛山三水区华侨中学招聘合同教师3人备考题库含答案详解ab卷
- 2026上半年贵州事业单位联考毕节市市直招聘44人备考题库带答案详解(完整版)
- 2026四川省引大济岷水资源开发有限公司第一批次招聘27人备考题库及答案详解(基础+提升)
- 2026广东佛山南海区狮山镇小塘第二幼儿园招聘备考题库有完整答案详解
- 积极思想培训
- 电杆基础施工专项方案
- 2026春译林8下单词表【Unit1-8】(可编辑版)
- 2026年《必背60题》抖音本地生活BD经理高频面试题包含详细解答
- 电影短片拍摄实践课件
- 电商平台对用户交易纠纷处理的机制或方案(2025完整版)
- 《经典常谈》导读课件教学
- 诚信单位创建申报资料标准模板
- 食堂承包居间合同范本
- 4输变电工程施工质量验收统一表式(电缆工程电气专业)-2024年版
- 传统元素与现代设计建筑融合创新
评论
0/150
提交评论