![Java 远程文件对接(处博)_第1页](http://file3.renrendoc.com/fileroot_temp3/2022-1/1/b2598742-eec2-4d9d-8d32-107678837d5a/b2598742-eec2-4d9d-8d32-107678837d5a1.gif)
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、java 远程文件对接(处博)以下代码即贴即用,第一次发博客,不足之处请大家多多指教! 1、配置文件:copyremotefperties src/perties 这里保存的都是键值对信息 interface name(no packgage) = implementation class 注重: a:【路径符号】【必需】是【/】【如:d:/home/publish】 b:【键key=值value】对【后面】【绝不允许有空格】【如:remote_host_ip=7】 remote_host_ip 远程机器ip login_account 远程机器
2、登录名 login_password 远程机器登录密码 share_doc_name 远程机器分享文件夹名(设置分享后必需授予读写权限) sourcepath 本地路径 targetpath 目标路径(真切路径=分享文件夹路径+目标路径) remote_host_ip=7 login_account=77 login_password=77 share_doc_name=vfs_home sourcepath=d:/home/publish targetpath=publish 2、导入jar包:jcifs-1.3.16.jar 3、读取配置文件中key对应的value类:
3、remoteconfigutil.java package com.remote; import java.io.ioexception; import java.util.properties; * 读取配置文件中key对应的value * author junjieqin public class remoteconfigutil private sing remote_host_ip; private string login_account; private string login_password; private string share_doc_name; private st
4、ring sourcepath; private string targetpath; /无参构造办法 public remoteconfigutil() try / 读取配置文件 properties prop = new properties(); prop.load(this.getclass().getclassloader().getresourceasstream("copyremotefperties"); / 按照 key 猎取 value remote_host_ip = prop.getproperty("remote_host_
5、ip"); login_account = prop.getproperty("login_account"); login_password = prop.getproperty("login_password"); share_doc_name = prop.getproperty("share_doc_name"); sourcepath = prop.getproperty("sourcepath"); targetpath = prop.getproperty("targetpath&
6、quot;); ch (ioexception e) e.printstacktrace(); public string getlogin_account() return login_account; public vo login_account(string login_account) login_account = login_account; public string getlogin_password() return login_password; public void setlogin_password(string login_password) login_pass
7、word = login_password; public string getremote_host_ip() return remote_host_ip; public void setremote_host_ip(string remote_host_ip) remote_host_ip = remote_host_ip; public string getshare_doc_name() return share_doc_name; public void setshare_doc_name(string share_doc_name) share_doc_name = share_d
8、oc_name; public string getsourcepath() return sourcepath; public void setsourcepath(string sourcepath) this.sourcepath = sourcepath; public string gettargetpath() return targetpath; public void settargetpath(string targetpath) this.targetpath = targetpath; 4、操作远程分享文件夹类: remotefileutil.java 按照需求挑选相应的
9、 method package com.remote; import java.io.bufferoutputstream; import java.io.bufferedreader; import java.io.file; import java.io.fileinputstream; import java.io.filenotfoundexception; import java.io.ioexception; import java.io.inputstream; import java.io.inputstreamreader; import java.io.outputstre
10、am; import .malfoedurlexception; import .unknownhostexception; import java.util.arraylist; import java.util.list; import jcifs.smb.smbexception; import jcifs.smb.smbfile; import jcifs.smb.smbfileinputstream; import jcifs.smb.smbfileoutputstream; /* * file name: remotefileutil.java * created by: junj
11、ieqin * checked in by: * date: 2011-9-6 * revision: 1.7 * description:操作远程分享文件夹类 * amendment history * modified date:2011-9-16 * modified by:junjieqin * change description:from local copy s to remote directory */ public class remotefileutil private arraylist filelist = new arraylist(); remoteconfigu
12、til rc = new remoteconfigutil(); private string remotehostip; /远程主机ip private string account; /登陆账户 private string password; /登陆密码 private string sharedocname; /分享文件夹名称 /* * 默认构造函数 public remotefileutil() this.remotehostip = rc.getremote_host_ip(); this.account = rc.getlogin_account(); this.password
13、 = rc.getlogin_password(); this.sharedocname = rc.getshare_doc_name(); /* * 构造函数 * param remotehostip 远程主机ip * param account 登陆账户 * param password 登陆密码 * param sharepath 分享文件夹路径 public remotefileutil(string remotehostip, string account, string password,string sharedocname) this.remotehostip = remote
14、hostip; this.account = account; this.password = password; this.sharedocname = sharedocname; /* * 对远程分享文件举行读取全部行 * param remotefilename 文件名 解释:参数为分享名目下的相对路径 * 若远程文件的路径为:sharedoctest.txt,则参数为test.txt(其中sharedoc为分享名目名称); * 若远程文件的路径为:sharedooctt.txt,则参数为doctext.txt; * return 文件的全部行 public list string re
15、adfile(string remotefilename) smbfile smbfile = null; bufferedreader reader = null; list string reltlines = null; /构建衔接字符串,并取得文件衔接 string constr = null; constr = "smb:/"+account+":"+password+""+remotehostip+"/"+sharedocname+"/"+remotefilename; try sm
16、bfile = new smbfile(constr); catch (malformedurlexception e) e.printstacktrace(); /创建reader try reader = new bufferedreader(new inputstreamreader(new smbfileinputstream(smbfile); catch (smbexception e) e.printstacktrace(); catch (malformedurlexception e) e.printstacktrace(); catch (unknownhostexcept
17、ion e) e.printstacktrace(); /循环对文件举行读取 string line; try line = reader.readline(); if(line != null line.length() 0) resultlines = new arraylist string while (line != null) resultlines.a(line); line = reader.readline(); catch (ioexception e) e.printstacktrace(); /返回 return resultlines; /* * 对远程分享文件举行写
18、入 * param is 本地文件的输入流 * param remotefilename 远程文件名 解释:参数为分享名目下的相对路径 * 若远程文件的路径为:sharedoctest.txt,则参数为test.txt(其中sharedoc为分享名目名称); * 若远程文件的路径为:sharedocdoctext.txt,则参数为doctext.txt; * return public boolean file(inputstream is,string remotefilename) smbfile smbfile = null; outputstream os = null; byte buffer = new byte1024*8; /构建衔接字符串,并取得文件衔接 string constr = null; constr = "smb:/"+account+":"+password+""+remotehostip+"/"+sharedocname+"/"+remotefilename; try smbfile = new s
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 商务秘书测验综合练习试题附答案
- 《镇痛镇静谵妄》课件
- 《燕子》公开课课件
- 《咖啡馆合作方案》课件
- 《洗衣机修理》课件
- 经济效益评价的基本方法课件
- 大学生科学实验报告解读
- 食品加工项目生产合作合同
- 中学生阅读经典作品感悟
- 中学生如何应对挫折征文
- 2025年小学督导工作计划
- 2024-2025学年部编版历史九年级上册期末复习练习题(含答案)
- 2025年北京生命科技研究院招聘笔试参考题库含答案解析
- 银行金融机构银行金融服务协议
- 基于ChatGPT的ESG评级体系实现机制研究
- GB/T 27697-2024立式油压千斤顶
- 《消防机器人相关技术研究》
- 《商务数据分析》课件-商务数据的分析
- 2024年考研政治真题及答案
- 【直播薪资考核】短视频直播电商部门岗位职责及绩效考核指标管理实施办法-市场营销策划-直播公司团队管理
- 项目设计报告范文高中
评论
0/150
提交评论