版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025第二次浙江嵊州市机关事业单位招聘编外工作人员和国有企业招聘工作人员23人笔试历年典型考点题库附带答案详解
- 2025江西吉安县县城生活污水处理厂招聘考试拟入闱投档分数线及部分岗位核减笔试历年难易错考点试卷带答案解析
- 2025安徽蚌埠竞先数据服务有限公司招聘暨综合笔试历年典型考点题库附带答案详解
- 2026年湖南吉利汽车职业技术学院单招职业技能笔试模拟试题带答案解析
- 2026年重庆旅游职业学院单招职业技能笔试模拟试题带答案解析
- 2026年河南交通职业技术学院单招综合素质考试备考试题附答案详解
- 2026年江西青年职业学院高职单招职业适应性测试备考题库带答案解析
- 2026年四川航天职业技术学院单招职业技能考试模拟试题带答案解析
- 2026年重庆工贸职业技术学院高职单招职业适应性测试模拟试题带答案解析
- 【发展趋势】硝酸铵钙行业上下游产业链、市场行情监测及投资发展前景研究报告
- 四川省成都市武侯区西川中学2024-2025学年八上期末数学试卷(解析版)
- 2026年《必背60题》抖音本地生活BD经理高频面试题包含详细解答
- 土方回填工程质量控制施工方案
- 渤海银行公司业务部客户经理岗位技能竞赛题库含答案
- 2025年海洋平台维护五年优化报告
- 聚合码商户协议书
- 2026贵州大数据产业集团有限公司第一次社会招聘考试题库新版
- 珠海高新区2025年下半年公开招聘公办中学事业编制教师备考题库及答案详解一套
- 2025年贵港市利恒投资集团有限公司公开招聘工作人员的备考题库及参考答案详解
- 辽宁省沈阳市皇姑区2024-2025学年七年级上学期期末道德与法治试卷
- 辽宁省盘锦市兴隆台区2024-2025学年九年级上学期期末数学试题
评论
0/150
提交评论